Class: Formtastic::Inputs::BooleanInput
- Inherits:
-
Object
- Object
- Formtastic::Inputs::BooleanInput
- Includes:
- Base
- Defined in:
- lib/formtastic/inputs/boolean_input.rb
Overview
Boolean inputs are used to render an input for a single checkbox, typically for attributes with a simple yes/no or true/false value. Boolean inputs are used by default for boolean database columns.
Instance Attribute Summary
Attributes included from Base
#builder, #method, #object, #object_name, #options, #template
Instance Method Summary collapse
- #check_box_html ⇒ Object
- #checked? ⇒ Boolean
- #checked_value ⇒ Object
- #hidden_field_html ⇒ Object
- #input_html_options ⇒ Object
- #label_html_options ⇒ Object
- #label_text_with_embedded_checkbox ⇒ Object
- #label_with_nested_checkbox ⇒ Object
- #to_html ⇒ Object
- #unchecked_value ⇒ Object
Methods included from Base
Methods included from Formtastic::Inputs::Base::Wrapping
#input_wrapping, #wrapper_dom_id, #wrapper_html_options
Methods included from Formtastic::Inputs::Base::Labelling
#label_from_options, #label_html, #label_text, #localized_label, #render_label?, #requirement_text, #requirement_text_or_proc
Methods included from Formtastic::Inputs::Base::Associations
#association, #association_primary_key, #belongs_to?, #reflection
Methods included from Formtastic::Inputs::Base::Fileish
Methods included from Formtastic::Inputs::Base::Validations
#column_limit, #limit, #not_required_through_negated_validation!, #not_required_through_negated_validation?, #optional?, #required?, #validation_integer_only?, #validation_limit, #validation_max, #validation_min, #validations, #validations?, #validator_relevant?
Methods included from Formtastic::Inputs::Base::Naming
#as, #attributized_method_name, #humanized_method_name, #input_name, #sanitized_method_name, #sanitized_object_name
Methods included from Formtastic::Inputs::Base::Hints
#hint?, #hint_html, #hint_text, #hint_text_from_options
Methods included from Formtastic::Inputs::Base::Errors
#error_first_html, #error_html, #error_keys, #error_list_html, #error_none_html, #error_sentence_html, #errors, #errors?
Methods included from Formtastic::Inputs::Base::Database
Methods included from Formtastic::Inputs::Base::Options
#formtastic_options, #input_options
Methods included from Formtastic::Inputs::Base::Html
Instance Method Details
#check_box_html ⇒ Object
65 66 67 |
# File 'lib/formtastic/inputs/boolean_input.rb', line 65 def check_box_html template.check_box_tag("#{object_name}[#{method}]", checked_value, checked?, ) end |
#checked? ⇒ Boolean
81 82 83 |
# File 'lib/formtastic/inputs/boolean_input.rb', line 81 def checked? object && ActionView::Helpers::InstanceTag.check_box_checked?(object.send(method), checked_value) end |
#checked_value ⇒ Object
73 74 75 |
# File 'lib/formtastic/inputs/boolean_input.rb', line 73 def checked_value [:checked_value] || '1' end |
#hidden_field_html ⇒ Object
42 43 44 |
# File 'lib/formtastic/inputs/boolean_input.rb', line 42 def hidden_field_html template.hidden_field_tag([:name], unchecked_value, :id => nil, :disabled => [:disabled] ) end |
#input_html_options ⇒ Object
77 78 79 |
# File 'lib/formtastic/inputs/boolean_input.rb', line 77 def {:name => "#{object_name}[#{method}]"}.merge(super) end |
#label_html_options ⇒ Object
54 55 56 57 58 59 |
# File 'lib/formtastic/inputs/boolean_input.rb', line 54 def .merge( :id => nil, :for => [:id] ) end |
#label_text_with_embedded_checkbox ⇒ Object
61 62 63 |
# File 'lib/formtastic/inputs/boolean_input.rb', line 61 def label_text << " " << check_box_html end |
#label_with_nested_checkbox ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/formtastic/inputs/boolean_input.rb', line 46 def label_with_nested_checkbox builder.label( method, , ) end |
#to_html ⇒ Object
35 36 37 38 39 40 |
# File 'lib/formtastic/inputs/boolean_input.rb', line 35 def to_html input_wrapping do hidden_field_html << label_with_nested_checkbox end end |
#unchecked_value ⇒ Object
69 70 71 |
# File 'lib/formtastic/inputs/boolean_input.rb', line 69 def unchecked_value [:unchecked_value] || '0' end |