Module: StimulusPlumbers::Form::Fields::Inputs::Search

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

Instance Method Summary collapse

Instance Method Details

#search_field(attribute, options = {}) ⇒ Object



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
# File 'lib/stimulus_plumbers/form/fields/inputs/search.rb', line 8

def search_field(attribute, options = {})
  html_native = options.delete(:html_native) { false }
  clearable   = options.delete(:clearable) { false }
  url         = options.delete(:url) { nil }
  choices     = options.delete(:options) { [] }

  Field.new(@template, **options).render(
    object,
    attribute,
    input_id: field_id(attribute)
  ) do |html_opts, opts, error|
    if html_native
      render_search_input(html_opts, opts, error, clearable: clearable) do |html_options|
        super(attribute, html_options)
      end
    else
      render_search_combobox(
        attribute,
        html_opts,
        error,
        url:       url,
        clearable: clearable
      ) do |combobox_opts, input_id, current_value|
        render_search_autocomplete(attribute, input_id, combobox_opts, error, choices, current_value)
      end
    end
  end
end