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

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

Defined Under Namespace

Modules: Grouped, Timezone, Weekday

Instance Method Summary collapse

Instance Method Details

#collection_select(attribute, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/stimulus_plumbers/form/fields/inputs/select.rb', line 24

def collection_select(
  attribute,
  collection,
  value_method,
  text_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, value_method, text_method, opts, merged)
    else
      render_select_dropdown(attribute, opts, merged, err: error, **icons) do
        collection.map { |item| [item.public_send(text_method), item.public_send(value_method)] }
      end
    end
  end
end

#select(attribute, choices = nil, options = {}, html_options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/stimulus_plumbers/form/fields/inputs/select.rb', line 8

def select(attribute, choices = nil, 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, choices, opts, merged)
    else
      render_select_dropdown(attribute, opts, merged, err: error, **icons) do
        Array(choices)
      end
    end
  end
end