digitig
digitig

Reputation: 2140

Rails number_field_tag won't accept a float even with :step

I have a number of entry fields laid out in a table, and one of the entries is:

<td><%= number_field_tag :elasticity, :step => 0.1 %></td>

When I enter a non-integer value such as 1.3 and try to post the form, it pops up with "Please enter a valid value. The two nearest valid values are 1 and 2". The up and down arrows increment by 1, too, not 0.1.

The HTML that is being produced is:

<td><input id="elasticity" name="elasticity" type="number" value="{:step=&gt;0.1}" /></td>

So I can't see why it's not accepting non-integer values. Can anybody suggest what I've done wrong?

Upvotes: 2

Views: 3953

Answers (1)

vee
vee

Reputation: 38645

The second argument to number_field_tag is value which is why you are seeing value="{:step=&gt;0.1}".

Call the helper as follows:

<td><%= number_field_tag :elasticity, nil, :step => 0.1 %></td>

Upvotes: 6

Related Questions