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
46
47
# 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 }
  Field.new(@template, **options).render(
    object,
    attribute,
    input_id: field_id(attribute)
  ) do |html_opts, opts, error|
    merged_html_opts = merge_html_options(html_options, html_opts, field_theme(:form_select, error: error))
    if html_native
      super(attribute, collection, value_method, text_method, opts, merged_html_opts)
    else
      render_select_dropdown(attribute, opts, merged_html_opts, err: error) 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 }
  Field.new(@template, **options).render(
    object,
    attribute,
    input_id: field_id(attribute)
  ) do |html_opts, opts, error|
    merged_html_opts = merge_html_options(html_options, html_opts, field_theme(:form_select, error: error))
    if html_native
      super(attribute, choices, opts, merged_html_opts)
    else
      render_select_dropdown(attribute, opts, merged_html_opts, err: error) { Array(choices) }
    end
  end
end