Class: Formatic::Toggle
- Inherits:
-
Base
- Object
- ViewComponent::Base
- ApplicationComponent
- Base
- Formatic::Toggle
- Defined in:
- app/components/formatic/toggle.rb
Overview
Stylish checkbox for a boolean attribute.
Instance Method Summary collapse
- #css_classes ⇒ Object
-
#dom_id ⇒ Object
There can be multiple checkboxes with the same attribute name on the page.
- #human_attribute_name ⇒ Object
-
#label_for_id ⇒ Object
So that the wrapper <label> references our custom checkbox.
Methods inherited from Base
#input_name, #param_key, #value, #wrapper
Methods inherited from ApplicationComponent
Constructor Details
This class inherits a constructor from Formatic::ApplicationComponent
Instance Method Details
#css_classes ⇒ Object
35 36 37 |
# File 'app/components/formatic/toggle.rb', line 35 def css_classes ::Formatic::Css.call('c-formatic-toggle__input', manual_class) end |
#dom_id ⇒ Object
There can be multiple checkboxes with the same attribute name on the page. To couple a <label> to its checkbox, make the checkbox ID unequivocal.
52 53 54 55 |
# File 'app/components/formatic/toggle.rb', line 52 def dom_id # For predictability in tests, maybe use something like `Time.now.nsec`? @dom_id ||= SecureRandom.hex(4) end |
#human_attribute_name ⇒ Object
44 45 46 47 48 |
# File 'app/components/formatic/toggle.rb', line 44 def human_attribute_name return unless f.object f.object.class.human_attribute_name(attribute_name) end |
#label_for_id ⇒ Object
So that the wrapper <label> references our custom checkbox.
40 41 42 |
# File 'app/components/formatic/toggle.rb', line 40 def label_for_id dom_id end |