Sha256: d7d66b09ac349457cef9f6c494655e3edce1c82350c477aa33578f0812a227a5

Contents?: true

Size: 1.2 KB

Versions: 7

Compression:

Stored size: 1.2 KB

Contents

module TaoForm
  module Components
    class CheckBoxComponent < FieldComponent

      attr_reader :checked_value, :unchecked_value, :checked, :disabled, :field_options

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

        init_field_options
      end

      def self.component_name
        :check_box
      end

      def render &block
        if block_given?
          super
        elsif builder && attribute_name
          super {
            builder.check_box attribute_name, field_options, checked_value, unchecked_value
          }
        else
          super {
            view.check_box_tag nil
          }
        end
      end

      private

      def default_options
        {class: 'tao-check-box'}
      end

      def init_field_options
        @field_options = {
          disabled: disabled
        }

        unless checked.nil?
          @field_options[:checked] = checked
        end
      end

    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
tao_form-1.0.0.beta.2 lib/tao_form/components/check_box_component.rb
tao_form-1.0.0.beta.1 lib/tao_form/components/check_box_component.rb
tao_form-0.2.3 lib/tao_form/components/check_box_component.rb
tao_form-0.2.2 lib/tao_form/components/check_box_component.rb
tao_form-0.2.1 lib/tao_form/components/check_box_component.rb
tao_form-0.2.0 lib/tao_form/components/check_box_component.rb
tao_form-0.1.10 lib/tao_form/components/check_box_component.rb