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

Inherits:
Trestle::Form::Field show all
Includes:
CheckBoxHelpers
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 included from CheckBoxHelpers

#custom?, #default_wrapper_class, #defaults, #inline?, #input_class, #label_class, #switch?

Methods inherited from Trestle::Form::Field

#defaults, #errors, #form_group, #normalize_options!, #readonly?

Constructor Details

#initialize(builder, template, name, options = {}, checked_value = "1", unchecked_value = "0") ⇒ CheckBox

Returns a new instance of CheckBox.



9
10
11
12
# File 'lib/trestle/form/fields/check_box.rb', line 9

def initialize(builder, template, name, options = {}, checked_value = "1", unchecked_value = "0")
  super(builder, template, name, options)
  @checked_value, @unchecked_value = checked_value, unchecked_value
end

Instance Attribute Details

#checked_valueObject (readonly)

Returns the value of attribute checked_value.



7
8
9
# File 'lib/trestle/form/fields/check_box.rb', line 7

def checked_value
  @checked_value
end

#unchecked_valueObject (readonly)

Returns the value of attribute unchecked_value.



7
8
9
# File 'lib/trestle/form/fields/check_box.rb', line 7

def unchecked_value
  @unchecked_value
end

Instance Method Details

#extract_wrapper_options!Object



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

def extract_wrapper_options!
  # Intentional no-op
end

#fieldObject



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

def field
  wrapper_class = options.delete(:class)
  wrapper_class = default_wrapper_class if wrapper_class.empty?

  (:div, class: wrapper_class) do
    safe_join([
      builder.raw_check_box(name, options.merge(class: input_class), checked_value, unchecked_value),
      builder.label(name, options[:label] || admin.human_attribute_name(name), class: label_class, value: (checked_value if options[:multiple]))
    ])
  end
end

#renderObject



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

def render
  field
end