Sha256: cf9bfba77b80a0e5b697169d7eef98354593c1d297eedc9b76f08fc7ca54d72a

Contents?: true

Size: 1.13 KB

Versions: 12

Compression:

Stored size: 1.13 KB

Contents

module Trestle
  class Form
    module Fields
      class CheckBox < Field
        include CheckBoxHelpers

        attr_reader :checked_value, :unchecked_value

        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

        def render
          field
        end

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

          content_tag(: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

        def extract_wrapper_options!
          # Intentional no-op
        end
      end
    end
  end
end

Trestle::Form::Builder.register(:check_box, Trestle::Form::Fields::CheckBox)

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
trestle-0.10.0 lib/trestle/form/fields/check_box.rb
trestle-0.10.0.pre2 lib/trestle/form/fields/check_box.rb
trestle-0.10.0.pre lib/trestle/form/fields/check_box.rb
trestle-0.9.8 lib/trestle/form/fields/check_box.rb
trestle-0.9.7 lib/trestle/form/fields/check_box.rb
trestle-0.9.6 lib/trestle/form/fields/check_box.rb
trestle-0.9.5 lib/trestle/form/fields/check_box.rb
trestle-0.9.4 lib/trestle/form/fields/check_box.rb
trestle-0.9.3 lib/trestle/form/fields/check_box.rb
trestle-0.9.2 lib/trestle/form/fields/check_box.rb
trestle-0.9.1 lib/trestle/form/fields/check_box.rb
trestle-0.9.0 lib/trestle/form/fields/check_box.rb