Class: TaoForm::Components::CheckBoxComponent

Inherits:
FieldComponent
  • Object
show all
Defined in:
lib/tao_form/components/check_box_component.rb

Direct Known Subclasses

SwitchComponent

Instance Attribute Summary collapse

Attributes inherited from FieldComponent

#attribute_name, #builder

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(view, builder = nil, attribute_name = nil, options = {}, checked_value = '1', unchecked_value = '0') ⇒ CheckBoxComponent

Returns a new instance of CheckBoxComponent.



7
8
9
10
11
12
# File 'lib/tao_form/components/check_box_component.rb', line 7

def initialize view, builder = nil, attribute_name = nil, options = {}, checked_value = '1', unchecked_value = '0'
  super view, builder, attribute_name, options
  @checked = @options.delete(:checked)
  @checked_value = checked_value
  @unchecked_value = unchecked_value
end

Instance Attribute Details

#checkedObject (readonly)

Returns the value of attribute checked.



5
6
7
# File 'lib/tao_form/components/check_box_component.rb', line 5

def checked
  @checked
end

#checked_valueObject (readonly)

Returns the value of attribute checked_value.



5
6
7
# File 'lib/tao_form/components/check_box_component.rb', line 5

def checked_value
  @checked_value
end

#unchecked_valueObject (readonly)

Returns the value of attribute unchecked_value.



5
6
7
# File 'lib/tao_form/components/check_box_component.rb', line 5

def unchecked_value
  @unchecked_value
end

Class Method Details

.component_nameObject



14
15
16
# File 'lib/tao_form/components/check_box_component.rb', line 14

def self.component_name
  :check_box
end

Instance Method Details

#render(&block) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/tao_form/components/check_box_component.rb', line 18

def render &block
  if block_given?
    super
  else
    super {
      builder.check_box attribute_name, {checked: checked}, checked_value, unchecked_value
    }
  end
end