Module: StimulusPlumbers::Form::Fields::Inputs::Select::Grouped

Included in:
Builder
Defined in:
lib/stimulus_plumbers/form/fields/inputs/select/grouped.rb

Instance Method Summary collapse

Instance Method Details

#grouped_collection_select(attribute, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {}) ⇒ Object



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
37
38
39
40
41
# File 'lib/stimulus_plumbers/form/fields/inputs/select/grouped.rb', line 9

def grouped_collection_select(
  attribute,
  collection,
  group_method,
  group_label_method,
  option_key_method,
  option_value_method,
  options = {},
  html_options = {}
)
  html_native   = options.delete(:html_native) { false }
  icon_leading  = options.delete(:icon_leading)
  icon_trailing = options.delete(:icon_trailing) { "chevron-down" }
  icons         = { icon_leading: icon_leading, icon_trailing: icon_trailing }
  with_select_field(attribute, options, html_options) do |opts, merged, error|
    if html_native
      super(
        attribute,
        collection,
        group_method,
        group_label_method,
        option_key_method,
        option_value_method,
        opts,
        merged
      )
    else
      render_select_dropdown(attribute, opts, merged, err: error, **icons) do
        build_grouped_choices(collection, group_label_method, group_method, option_key_method, option_value_method)
      end
    end
  end
end