Sha256: 76122d66b5053b80abca7955df3e046d212b2ca401a8f85167bf4a81397f9530

Contents?: true

Size: 985 Bytes

Versions: 1

Compression:

Stored size: 985 Bytes

Contents

module FormGroups
  mattr_accessor(:field_class) { 'field' }
  mattr_accessor(:field_error_class) { 'field-error' }
  mattr_accessor(:map_validators) { true }

  mattr_reader :validator_mapping do
    mappings = {}

    mappings[ActiveModel::Validations::LengthValidator] = Proc.new do |validator, result|
      result['minlength'] = validator.options[:minimum] if validator.options[:minimum]
      result['maxlength'] = validator.options[:maximum] if validator.options[:maximum]
    end

    mappings[ActiveModel::Validations::PresenceValidator] = Proc.new do |validator, result|
      result['required'] = 'true'
      result['aria-required'] = 'true'
    end

    mappings[ActiveModel::Validations::InclusionValidator] = Proc.new do |validator, result|
      range = validator.options[:within]

      if range.is_a? Range
        result['min'] = range.min
        result['max'] = range.max
      end
    end

    mappings
  end

  def self.configure &block
    yield self
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
formgroups-rails-0.0.4 lib/form_groups/configuration.rb