Sha256: 7fe3e5796f0ced5d315bd8ef6728b6055eee508bde62052766f1525871c7f100

Contents?: true

Size: 1.06 KB

Versions: 6

Compression:

Stored size: 1.06 KB

Contents

module Trestle
  class Form
    module Fields
      class FormGroup < Field
        def render
          options[:class] << 'has-error' if errors.any?

          content_tag(:div, options) do
            concat label unless options[:label] == false
            concat block.call if block
            concat help_message if options[:help]
            concat error_message if errors.any?
          end
        end

        def help_message
          content_tag(:p, options[:help], class: "help-block")
        end

        def error_message
          content_tag(:p, class: "help-block") do
            safe_join([icon("fa fa-warning"), errors.first], " ")
          end
        end

        def label
          builder.label(name, options[:label], class: ["control-label", ("sr-only" if options[:hide_label])].compact)
        end

        def defaults
          super.merge(class: ["form-group"])
        end

        def extract_options!
          # Do not call super
        end
      end
    end
  end
end

Trestle::Form::Builder.register(:form_group, Trestle::Form::Fields::FormGroup)

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
trestle-0.8.6 lib/trestle/form/fields/form_group.rb
trestle-0.8.5 lib/trestle/form/fields/form_group.rb
trestle-0.8.4 lib/trestle/form/fields/form_group.rb
trestle-0.8.3 lib/trestle/form/fields/form_group.rb
trestle-0.8.2 lib/trestle/form/fields/form_group.rb
trestle-0.8.0 lib/trestle/form/fields/form_group.rb