Class: Tailwinds::Form::MultiselectComponent
Overview
Tailwind-styled multi-select field
Instance Method Summary
collapse
#component
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object
65
66
67
68
69
70
71
72
73
|
# File 'app/components/tailwinds/form/multiselect_component.rb', line 65
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_render ⇒ Object
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
|
#controller ⇒ Object
22
23
24
25
26
27
|
# File 'app/components/tailwinds/form/multiselect_component.rb', line 22
def controller
controllers = [:multiselect]
controllers << external_action.split('->').last.split('#').first if external_action
controllers += external_controllers
controllers.join(' ')
end
|
#multiselect_hash ⇒ Object
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:, on_change:
}.transform_keys { |key| key.to_s.gsub('_', '-') }
end
|