Sha256: 2ff9f9011190413d6fd049ebfc2c86e3d72df3b9b208096eaa541e21326789dd

Contents?: true

Size: 895 Bytes

Versions: 1

Compression:

Stored size: 895 Bytes

Contents

module GenericFormFor 
  module Inputs
    class BooleanInput
      include Base
      
      def input_html_options
        {:checked => checked?}.merge(super).except(*[:checked_value, :unchecked_value, :value])
      end
      
      def input_html(config_options={})
        template.concat builder.check_box(method, merge_html_options(input_html_options,config_options), checked_value, unchecked_value)
      end
      
      def unchecked_value
        options[:unchecked_value] || '0'
      end

      def checked_value
        options[:checked_value] || '1'
      end
      
      def checked?
        if options.key?(:value) 
          return checked_value.to_s == options[:value].to_s
        end
        return false unless object.respond_to?(method)
        checked_value.to_s == object.send(method).to_s
      end
      
      def required?
        false
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
generic_form_for-0.0.1 lib/generic_form_for/inputs/boolean_input.rb