Class: Tailwinds::Form::MultiselectComponent

Inherits:
TailwindComponent show all
Defined in:
app/components/tailwinds/form/multiselect_component.rb

Overview

Tailwind-styled multi-select field

Instance Method Summary collapse

Methods included from Tramway::Helpers::ComponentHelper

#component

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name) ⇒ Object (private)



48
49
50
51
52
53
54
55
56
# File 'app/components/tailwinds/form/multiselect_component.rb', line 48

def method_missing(method_name, *, &)
  component = component_name(method_name)

  if method_name.to_s.include?('_') && Object.const_defined?(component)
    render(component.constantize.new(*, &))
  else
    super
  end
end

Instance Method Details

#before_renderObject



9
10
11
12
13
# File 'app/components/tailwinds/form/multiselect_component.rb', line 9

def before_render
  @collection = collection.map do |(text, value)|
    { text:, value: }
  end.to_json
end

#controllerObject



22
23
24
# File 'app/components/tailwinds/form/multiselect_component.rb', line 22

def controller
  :multiselect
end

#multiselect_hashObject



15
16
17
18
19
20
# File 'app/components/tailwinds/form/multiselect_component.rb', line 15

def multiselect_hash
  {
    controller:, selected_item_template:, multiselect_selected_items_value:, dropdown_container:, item_container:,
    items:, action:, select_as_input:, placeholder:, value:
  }.transform_keys { |key| key.to_s.gsub('_', '-') }
end