Sha256: 2f661060a6635cb9d1494454d7f4125174fed7a9906a972f446011c1c10ed8fd

Contents?: true

Size: 697 Bytes

Versions: 1

Compression:

Stored size: 697 Bytes

Contents

module HungryForm
  module Elements
    class CheckboxField < Base::ActiveElement
      def set_value
        self.value = resolver.params[name] || attributes.delete(:value)

        if value == 0
          attributes.delete(:checked)
        else
          self.value = 1
          self.attributes[:checked] = true
        end
      end

      def checked?
        !!attributes[:checked]
      end

      # Overriding the Validator methods
      module Validator
        def self.required(element, rule)
          if rule.respond_to? :call
            rule.call(element)
          else
            'is required' if element.value == 0 && rule
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hungryform-0.0.8 lib/hungryform/elements/checkbox_field.rb