Module: StimulusPlumbers::Form::Fields::Combobox
- Included in:
- Builder
- Defined in:
- lib/stimulus_plumbers/form/fields/combobox.rb
Constant Summary collapse
- COMPONENT_CLASS =
{ autocomplete: Components::Combobox::Autocomplete, date: Components::Combobox::Date, dropdown: Components::Combobox::Dropdown, time: Components::Combobox::Time }.freeze
Instance Method Summary collapse
- #build_combobox_wrapper(klass, attribute, field, current_value, options, rails_opts) ⇒ Object
- #combobox_field(attribute, type:, options: [], **html_options) ⇒ Object
Instance Method Details
#build_combobox_wrapper(klass, attribute, field, current_value, options, rails_opts) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/stimulus_plumbers/form/fields/combobox.rb', line 28 def build_combobox_wrapper(klass, attribute, field, current_value, , rails_opts) popover = klass.new(@template).render(options: , value: current_value, **rails_opts) opts = klass.default_opts.deep_merge( input: { name: field_name(attribute), value: current_value }, popover: { content: popover } ) Components::Combobox.new(@template).render( base_id: field_id(attribute), options: opts, **field_theme(:form_combobox, error: field.error?), **field.html_opts ) end |
#combobox_field(attribute, type:, options: [], **html_options) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/stimulus_plumbers/form/fields/combobox.rb', line 14 def combobox_field(attribute, type:, options: [], **) klass = COMPONENT_CLASS.fetch(type) do raise ArgumentError, "unsupported combobox type #{type.inspect}. Must be one of: #{COMPONENT_CLASS.keys.join(", ")}" end rails_opts, field_opts = () field = build_field(attribute, field_opts) current_value = object&.public_send(attribute) wrapper = build_combobox_wrapper(klass, attribute, field, current_value, , rails_opts) render_field(field, wrapper) end |