Sha256: c749f9a817fb62aa69525ab618cd24220e9db1e6f0d0cb1ba3fecd3089044ef1
Contents?: true
Size: 1.83 KB
Versions: 3
Compression:
Stored size: 1.83 KB
Contents
module Trestle class Form module Fields class FormGroup < Field WRAPPER_OPTIONS = [:help, :label, :hide_label] def initialize(builder, template, name=nil, options={}, &block) # Normalize options passed as name parameter name, options = nil, name if name.is_a?(Hash) super(builder, template, name, options, &block) end def render content_tag(:div, options.except(*WRAPPER_OPTIONS)) do concat label if name && options[:label] != false concat template.capture(&block) if block concat help_message if options[:help] concat error_messages if name && errors.any? end end def help_message classes = ["form-text"] if options[:help].is_a?(Hash) message = options[:help][:text] classes << "floating" if options[:help][:float] else message = options[:help] end content_tag(:p, message, class: classes) end def error_messages content_tag(:ul, class: "invalid-feedback") do safe_join(errors.map { |error| content_tag(:li, safe_join([icon("fa fa-warning"), error], " ")) }, "\n") end end def label builder.label(name, options[:label], class: ["form-label", ("visually-hidden" if options[:hide_label])].compact) end def defaults Trestle::Options.new(class: ["form-group"]) end protected def extract_wrapper_options! # Intentional no-op end def error_class "has-error" end def error_keys name ? super : [] end end end end end Trestle::Form::Builder.register(:form_group, Trestle::Form::Fields::FormGroup)
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
trestle-0.10.0 | lib/trestle/form/fields/form_group.rb |
trestle-0.10.0.pre2 | lib/trestle/form/fields/form_group.rb |
trestle-0.10.0.pre | lib/trestle/form/fields/form_group.rb |