number_field_tag(name, value = nil, options = {}) public

Creates a number field.

Options

  • :min - The minimum acceptable value.

  • :max - The maximum acceptable value.

  • :in - A range specifying the :min and :max values.

  • :step - The acceptable value granularity.

  • Otherwise accepts the same options as text_field_tag.

Examples

number_field_tag 'quantity', nil, :in => 1...10
# => <input id="quantity" name="quantity" min="1" max="9" type="number" />
Show source
Register or log in to add new notes.
March 19, 2015 - (v4.0.2)
0 thanks

number_field tag does not accept the same options as text_field_tag

number_field_tag does not accept the size or maxlength options; the max option for number_field_tag is used to control the size of the field. According to W3 http://www.w3.org/TR/html-markup/input.number.html , placeholder should be accepted, but I don’t find that this works in the way it works for text_field_tag.