Class: HungryForm::Elements::CheckboxField
- Inherits:
-
Base::ActiveElement
- Object
- Base::Element
- Base::ActiveElement
- HungryForm::Elements::CheckboxField
- Defined in:
- lib/hungryform/elements/checkbox_field.rb
Defined Under Namespace
Modules: Validator
Instance Attribute Summary
Attributes inherited from Base::ActiveElement
Attributes inherited from Base::Element
#attributes, #dependency, #label, #name, #placeholders, #resolver, #visible
Instance Method Summary collapse
Methods inherited from Base::ActiveElement
#clear_error, #initialize, #invalid?, #valid?, #validate_rule
Methods inherited from Base::Element
#configuration, #dependency_json, #initialize
Methods included from Base::Hashable
Constructor Details
This class inherits a constructor from HungryForm::Elements::Base::ActiveElement
Instance Method Details
#checked? ⇒ Boolean
15 16 17 |
# File 'lib/hungryform/elements/checkbox_field.rb', line 15 def checked? !!attributes[:checked] end |
#set_value ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/hungryform/elements/checkbox_field.rb', line 4 def set_value self.value = resolver.params[name] || attributes.delete(:value) || 0 if value.to_i == 0 attributes.delete(:checked) else self.value = 1 self.attributes[:checked] = true end end |