Class: GenericFormFor::Inputs::BooleanInput

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/generic_form_for/inputs/boolean_input.rb

Instance Attribute Summary

Attributes included from Base

#builder, #column, #method, #object, #object_name, #options, #template

Instance Method Summary collapse

Methods included from Base

#autofocus?, #default_input_options, #form_builder_options, #initialize, #input_html_class, #input_options, #merge_html_options, #to_html, #wrap_in

Methods included from GenericFormFor::Inputs::Base::ErrorMessage

#error_html, #error_html_options, #errors, #errors?, #render_error?

Methods included from GenericFormFor::Inputs::Base::Label

#label_html, #label_html_options, #label_text, #render_label?, #requirement_text, #translated_label

Methods included from GenericFormFor::Inputs::Base::Validations

#decimals, #limit, #limits_from_validations, #maximal_number, #minimal_number, #required_from_validations?

Methods included from GenericFormFor::Inputs::Base::Hint

#hint_html, #hint_html_options, #hint_text, #render_hint?

Methods included from GenericFormFor::I18n

#translate, #translate_action, #translate_hint, #translate_label, #translate_legend, #translate_placeholder

Instance Method Details

#checked?Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
# File 'lib/generic_form_for/inputs/boolean_input.rb', line 22

def checked?
  if options.key?(:value) 
    return checked_value.to_s == options[:value].to_s
  end
  return false unless object.respond_to?(method)
  checked_value.to_s == object.send(method).to_s
end

#checked_valueObject



18
19
20
# File 'lib/generic_form_for/inputs/boolean_input.rb', line 18

def checked_value
  options[:checked_value] || '1'
end

#input_html(config_options = {}) ⇒ Object



10
11
12
# File 'lib/generic_form_for/inputs/boolean_input.rb', line 10

def input_html(config_options={})
  template.concat builder.check_box(method, merge_html_options(input_html_options,config_options), checked_value, unchecked_value)
end

#input_html_optionsObject



6
7
8
# File 'lib/generic_form_for/inputs/boolean_input.rb', line 6

def input_html_options
  {:checked => checked?}.merge(super).except(*[:checked_value, :unchecked_value, :value])
end

#required?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/generic_form_for/inputs/boolean_input.rb', line 30

def required?
  false
end

#unchecked_valueObject



14
15
16
# File 'lib/generic_form_for/inputs/boolean_input.rb', line 14

def unchecked_value
  options[:unchecked_value] || '0'
end