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

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

Instance Method Summary collapse

Instance Method Details

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



7
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/stimulus_plumbers/form/fields/search.rb', line 7

def search_field(attribute, options = {})
  rails_opts, form_field_opts = extract_options(options)
  clearable = form_field_opts.delete(:clearable) { false }
  field     = build_field(attribute, form_field_opts)

  input_html = if clearable
                 input_opts = merge_html_options(
                   rails_opts,
                   field_theme(:form_input, error: field.error?),
                   field.html_opts,
                   { "data-input-search-target": "input", inputmode: "search" }
                 )
                 build_input_group(
                   super(attribute, input_opts),
                   field,
                   trailing:          clear_button,
                   "data-controller": "input-search",
                   role:              "search"
                 )
               else
                 html_opts = merge_html_options(
                   rails_opts,
                   field_theme(:form_input, error: field.error?),
                   field.html_opts
                 )
                 super(attribute, html_opts)
               end

  render_field(field, input_html)
end