I have the following code in my view
.fields
= f.label :minimum_mpg
%br
= f.number_field :mpg_min, :in => 0..100, :type => 'float' , :precision => 2
I want to restrict the input from 0 to 100, but when I enter in negative numbers they are accepted. I think it has something to do with changing the type to float. The input needs to be able to accept floats though.
Thanks for you help.
Your
:type => 'float'line is overriding the defaulttype="number"part of the HTML tag that is generated, effectively turning it back into a standard text field instead of a number field.If you need to accept two decimal places, you could do something like this. However, clicking the up/down arrows on the field will only increment 0.01 at a time.