1
0
Fork 0
mirror of https://github.com/heartcombo/simple_form.git synced 2022-11-09 12:19:26 -05:00

Set the max attribute when there's a <= validation

This commit is contained in:
Daniel Schierbeck 2010-09-05 23:27:54 +08:00 committed by Carlos Antonio da Silva
parent c81f3ca994
commit abeb06a1db
3 changed files with 7 additions and 1 deletions

View file

@ -34,6 +34,7 @@ module SimpleForm
options = num_validator.__send__(:options)
input_options[:min] ||= options[:greater_than_or_equal_to]
input_options[:max] ||= options[:less_than_or_equal_to]
end
end
end

View file

@ -59,6 +59,11 @@ class InputTest < ActionView::TestCase
assert_select 'input[min=18]'
end
test 'input should generate a max attribute when such a validation exists in the model' do
with_input_for @validating_user, :age, :integer
assert_select 'input[max=99]'
end
test 'input should generate a float text field for float attributes ' do
with_input_for @user, :age, :float
assert_select 'input[type=number].float#user_age'

View file

@ -118,5 +118,5 @@ class ValidatingUser < User
include ActiveModel::Validations
validates :name, :presence => true
validates :company, :presence => true
validates_numericality_of :age, :greater_than_or_equal_to => 18
validates_numericality_of :age, :greater_than_or_equal_to => 18, :less_than_or_equal_to => 99
end