Add a step attribute when a numeric field is integer only

This commit is contained in:
Daniel Schierbeck 2010-09-05 23:32:13 +08:00 committed by Carlos Antonio da Silva
parent abeb06a1db
commit 88e6dd51b0
3 changed files with 12 additions and 3 deletions

View File

@ -33,8 +33,9 @@ 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]
input_options[:min] ||= options[:greater_than_or_equal_to]
input_options[:max] ||= options[:less_than_or_equal_to]
input_options[:step] ||= options[:only_integer] && 1
end
end
end

View File

@ -64,6 +64,11 @@ class InputTest < ActionView::TestCase
assert_select 'input[max=99]'
end
test 'input should get the step attr from a numericality validation' do
with_input_for @validating_user, :age, :integer
assert_select 'input[step=1]'
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,8 @@ class ValidatingUser < User
include ActiveModel::Validations
validates :name, :presence => true
validates :company, :presence => true
validates_numericality_of :age, :greater_than_or_equal_to => 18, :less_than_or_equal_to => 99
validates_numericality_of :age,
:greater_than_or_equal_to => 18,
:less_than_or_equal_to => 99,
:only_integer => true
end