Add a step attribute when a numeric field is integer only
This commit is contained in:
parent
abeb06a1db
commit
88e6dd51b0
|
@ -35,6 +35,7 @@ module SimpleForm
|
|||
|
||||
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
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue