Class: Trestle::Form::Fields::CheckBox
- Inherits:
-
Trestle::Form::Field
- Object
- Trestle::Form::Field
- Trestle::Form::Fields::CheckBox
- 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
- #defaults ⇒ Object
- #field ⇒ Object
-
#initialize(builder, template, name, options = {}, checked_value = "1", unchecked_value = "0") ⇒ CheckBox
constructor
A new instance of CheckBox.
- #render ⇒ Object
Methods inherited from Trestle::Form::Field
#errors, #extract_options!, #form_group
Constructor Details
#initialize(builder, template, name, options = {}, checked_value = "1", unchecked_value = "0") ⇒ CheckBox
Returns a new instance of CheckBox.
7 8 9 10 11 12 |
# File 'lib/trestle/form/fields/check_box.rb', line 7 def initialize(builder, template, name, = {}, checked_value = "1", unchecked_value = "0") super(builder, template, name, ) @options = defaults.merge() @checked_value, @unchecked_value = checked_value, unchecked_value end |
Instance Attribute Details
#checked_value ⇒ Object (readonly)
Returns the value of attribute checked_value.
5 6 7 |
# File 'lib/trestle/form/fields/check_box.rb', line 5 def checked_value @checked_value end |
#unchecked_value ⇒ Object (readonly)
Returns the value of attribute unchecked_value.
5 6 7 |
# File 'lib/trestle/form/fields/check_box.rb', line 5 def unchecked_value @unchecked_value end |
Instance Method Details
#defaults ⇒ Object
29 30 31 |
# File 'lib/trestle/form/fields/check_box.rb', line 29 def defaults super.merge(class: ["checkbox"]) end |
#field ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/trestle/form/fields/check_box.rb', line 18 def field content_tag(:div, class: .delete(:class)) do content_tag(:label) do safe_join([ builder.raw_check_box(name, , checked_value, unchecked_value), [:label] || admin.human_attribute_name(name) ], " ") end end end |
#render ⇒ Object
14 15 16 |
# File 'lib/trestle/form/fields/check_box.rb', line 14 def render field end |