Class: TemplateForm::GroupedSelectInput
- Defined in:
- lib/template_form/grouped_select_input.rb
Constant Summary collapse
- OPTION_KEYS =
%i[ include_blank prompt index disabled selected ]
Instance Method Summary collapse
-
#initialize(builder, attribute_name, options) ⇒ GroupedSelectInput
constructor
A new instance of GroupedSelectInput.
- #render ⇒ Object
Constructor Details
#initialize(builder, attribute_name, options) ⇒ GroupedSelectInput
Returns a new instance of GroupedSelectInput.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/template_form/grouped_select_input.rb', line 8 def initialize(builder, attribute_name, ) @builder = builder @attribute_name = attribute_name @view = .delete(:view) @form_type = .delete(:form_type) || builder.form_type @collection = .delete(:collection).to_a # Use the `:label` option to override the default label text. # Use `label: false` to indicate no label should be shown (check `has_label` in the template). @has_label = !(.has_key?(:label) && [:label] == false) @label_text = .delete(:label) || '' @label_options = Hash.new { |h,k| h[k] = '' }.update(.delete(:label_options) || {}) @hint_text = .delete(:hint) || '' @group_method = .delete(:group_method) || :last @group_label_method = .delete(:group_label_method) || :first @option_key_method = .delete :option_key_method @option_value_method = .delete :option_value_method data_attributes = (.delete(:data) || {}).transform_keys { |k| "data-#{k}" } @options, @html_options = .partition { |k,_| OPTION_KEYS.include? k }.map(&:to_h) @html_options.merge! data_attributes @html_options[:class] ||= '' end |
Instance Method Details
#render ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/template_form/grouped_select_input.rb', line 38 def render template.render( builder, attribute_name: attribute_name, collection: collection, has_label: has_label, label_text: label_text, label_options: , hint_text: hint_text, options: , html_options: , errors: errors, group_method: group_method, group_label_method: group_label_method, option_key_method: option_key_method, option_value_method: option_value_method, view: view ).html_safe end |