Sha256: b5a3d031474416d8cd02516c76e6d7583932521e82a256af424de63f3c2cffb6

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

module Trestle
  class Form
    module Fields
      class GroupedCollectionSelect < Field
        attr_reader :collection, :group_method, :group_label_method, :option_key_method, :option_value_method, :html_options

        def initialize(builder, template, name, collection, group_method, group_label_method, option_key_method, option_value_method, options={}, html_options={})
          super(builder, template, name, options)

          @collection, @group_method, @group_label_method, @option_key_method, @option_value_method = collection, group_method, group_label_method, option_key_method, option_value_method
          @html_options = default_html_options.merge(html_options)
        end

        def field
          builder.raw_grouped_collection_select(name, collection, group_method, group_label_method, option_key_method, option_value_method, options, html_options)
        end

        def default_html_options
          Trestle::Options.new(class: ["form-control"])
        end
      end
    end
  end
end

Trestle::Form::Builder.register(:grouped_collection_select, Trestle::Form::Fields::GroupedCollectionSelect)

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
trestle-0.8.3 lib/trestle/form/fields/grouped_collection_select.rb
trestle-0.8.2 lib/trestle/form/fields/grouped_collection_select.rb
trestle-0.8.0 lib/trestle/form/fields/grouped_collection_select.rb