Sha256: 1cc7502d7ec79d1688468a933c28f1e5b0c5909182ea967a7a70c92f18360635

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 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-select"], disabled: disabled? || readonly?, data: { controller: "select" })
        end
      end
    end
  end
end

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
trestle-0.10.1 lib/trestle/form/fields/grouped_collection_select.rb
trestle-0.10.0 lib/trestle/form/fields/grouped_collection_select.rb
trestle-0.10.0.pre2 lib/trestle/form/fields/grouped_collection_select.rb
trestle-0.10.0.pre lib/trestle/form/fields/grouped_collection_select.rb