Class: Trestle::Form::Fields::CheckBox
- Inherits:
-
Trestle::Form::Field
- Object
- Trestle::Form::Field
- Trestle::Form::Fields::CheckBox
- Includes:
- CheckBoxHelpers
- Defined in:
- lib/trestle/form/fields/check_box.rb
Instance Attribute Summary collapse
-
#checked_value ⇒ Object
readonly
Returns the value of attribute checked_value.
-
#unchecked_value ⇒ Object
readonly
Returns the value of attribute unchecked_value.
Attributes inherited from Trestle::Form::Field
#block, #builder, #name, #options, #template
Instance Method Summary collapse
- #extract_wrapper_options! ⇒ Object
- #field ⇒ Object
-
#initialize(builder, template, name, options = {}, checked_value = "1", unchecked_value = "0") ⇒ CheckBox
constructor
A new instance of CheckBox.
- #render ⇒ Object
Methods included from CheckBoxHelpers
#default_wrapper_class, #defaults, #inline?, #input_class, #label_class, #switch?
Methods inherited from Trestle::Form::Field
#defaults, #disabled?, #errors, #form_group, #normalize_options!, #readonly?
Constructor Details
#initialize(builder, template, name, options = {}, checked_value = "1", unchecked_value = "0") ⇒ CheckBox
Returns a new instance of CheckBox.
9 10 11 12 |
# File 'lib/trestle/form/fields/check_box.rb', line 9 def initialize(builder, template, name, = {}, checked_value = "1", unchecked_value = "0") super(builder, template, name, ) @checked_value, @unchecked_value = checked_value, unchecked_value end |
Instance Attribute Details
#checked_value ⇒ Object (readonly)
Returns the value of attribute checked_value.
7 8 9 |
# File 'lib/trestle/form/fields/check_box.rb', line 7 def checked_value @checked_value end |
#unchecked_value ⇒ Object (readonly)
Returns the value of attribute unchecked_value.
7 8 9 |
# File 'lib/trestle/form/fields/check_box.rb', line 7 def unchecked_value @unchecked_value end |
Instance Method Details
#extract_wrapper_options! ⇒ Object
30 31 32 |
# File 'lib/trestle/form/fields/check_box.rb', line 30 def # Intentional no-op end |
#field ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/trestle/form/fields/check_box.rb', line 18 def field wrapper_class = .delete(:class) wrapper_class = default_wrapper_class if wrapper_class.empty? tag.div(class: wrapper_class) do safe_join([ builder.raw_check_box(name, .merge(class: input_class), checked_value, unchecked_value), builder.label(name, [:label] || admin.human_attribute_name(name), class: label_class, value: (checked_value if [:multiple])) ]) end end |
#render ⇒ Object
14 15 16 |
# File 'lib/trestle/form/fields/check_box.rb', line 14 def render field end |