Add a step attribute when a numeric field is integer only
This commit is contained in:
parent
abeb06a1db
commit
88e6dd51b0
|
@ -33,8 +33,9 @@ module SimpleForm
|
||||||
|
|
||||||
options = num_validator.__send__(:options)
|
options = num_validator.__send__(:options)
|
||||||
|
|
||||||
input_options[:min] ||= options[:greater_than_or_equal_to]
|
input_options[:min] ||= options[:greater_than_or_equal_to]
|
||||||
input_options[:max] ||= options[:less_than_or_equal_to]
|
input_options[:max] ||= options[:less_than_or_equal_to]
|
||||||
|
input_options[:step] ||= options[:only_integer] && 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -64,6 +64,11 @@ class InputTest < ActionView::TestCase
|
||||||
assert_select 'input[max=99]'
|
assert_select 'input[max=99]'
|
||||||
end
|
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
|
test 'input should generate a float text field for float attributes ' do
|
||||||
with_input_for @user, :age, :float
|
with_input_for @user, :age, :float
|
||||||
assert_select 'input[type=number].float#user_age'
|
assert_select 'input[type=number].float#user_age'
|
||||||
|
|
|
@ -118,5 +118,8 @@ class ValidatingUser < User
|
||||||
include ActiveModel::Validations
|
include ActiveModel::Validations
|
||||||
validates :name, :presence => true
|
validates :name, :presence => true
|
||||||
validates :company, :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
|
end
|
||||||
|
|
Loading…
Reference in New Issue