Class: FoxTail::CheckboxComponent
- Inherits:
-
BaseComponent
show all
- Includes:
- FoxTail::Concerns::Formable, FoxTail::Concerns::HasStimulusController
- Defined in:
- app/components/fox_tail/checkbox_component.rb
Defined Under Namespace
Classes: StimulusController
Instance Attribute Summary
#html_attributes
Class Method Summary
collapse
Instance Method Summary
collapse
classname_merger, #initialize, stimulus_merger, use_stimulus?, #with_html_attributes, #with_html_class
Methods inherited from Base
fox_tail_config
Class Method Details
.stimulus_controller_name ⇒ Object
78
79
80
|
# File 'app/components/fox_tail/checkbox_component.rb', line 78
def stimulus_controller_name
"form-field"
end
|
Instance Method Details
#before_render ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'app/components/fox_tail/checkbox_component.rb', line 48
def before_render
super
if multiple?
add_default_name_and_id_for_value checked_value
else
add_default_name_and_id
end
html_attributes[:type] = :checkbox
html_attributes[:class] = classnames theme.apply(:root, self), html_class
html_attributes[:value] = checked_value
html_attributes[:checked] = checked?
end
|
#call ⇒ Object
63
64
65
66
67
68
|
# File 'app/components/fox_tail/checkbox_component.rb', line 63
def call
capture do
concat tag.input(hidden_attributes) if include_hidden?
concat tag.input(html_attributes)
end
end
|
#checked? ⇒ Boolean
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'app/components/fox_tail/checkbox_component.rb', line 21
def checked?
return !!options[:checked] if options.key? :checked
case value
when TrueClass, FalseClass
value == !!checked_value
when NilClass
false
when String
value == checked_value
else
if value.respond_to?(:include?)
value.map(&:to_s).include?(checked_value.to_s)
else
value.to_i == checked_value.to_i
end
end
end
|
#stimulus_controller_options ⇒ Object
44
45
46
|
# File 'app/components/fox_tail/checkbox_component.rb', line 44
def stimulus_controller_options
{}
end
|
#use_stimulus? ⇒ Boolean
40
41
42
|
# File 'app/components/fox_tail/checkbox_component.rb', line 40
def use_stimulus?
super && controlled?
end
|
#value ⇒ Object
17
18
19
|
# File 'app/components/fox_tail/checkbox_component.rb', line 17
def value
options[:value] ||= value_from_object
end
|