Class: Trestle::Form::Fields::CheckBox

Inherits:
Trestle::Form::Field show all
Defined in:
lib/trestle/form/fields/check_box.rb

Instance Attribute Summary collapse

Attributes inherited from Trestle::Form::Field

#block, #builder, #name, #options, #template

Instance Method Summary collapse

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, options = {}, checked_value = "1", unchecked_value = "0")
  super(builder, template, name, options)

  @options = defaults.merge(options)
  @checked_value, @unchecked_value = checked_value, unchecked_value
end

Instance Attribute Details

#checked_valueObject (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_valueObject (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

#defaultsObject



29
30
31
# File 'lib/trestle/form/fields/check_box.rb', line 29

def defaults
  super.merge(class: ["checkbox"])
end

#fieldObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/trestle/form/fields/check_box.rb', line 18

def field
  (:div, class: options.delete(:class)) do
    (:label) do
      safe_join([
        builder.raw_check_box(name, options, checked_value, unchecked_value),
        options[:label] || admin.human_attribute_name(name)
      ], " ")
    end
  end
end

#renderObject



14
15
16
# File 'lib/trestle/form/fields/check_box.rb', line 14

def render
  field
end