skip to Main Content

There is an input field with the type="number" loaded with default decimal value. When I want to remove the decimal and submit the form, It gives me validation error (on Chrome) and forces to use decimal. Should I use any special attribute or this is a bug? Besides I don’t want to use step="1" because sometimes I may need decimals.

<form action="?">
<input type="number" value="123.2423">
<input type="submit" value="submit">
</form>

2

Answers


  1. From MDN web docs –

    The default stepping value for number inputs is 1, allowing only
    integers to be entered—unless the stepping base is not an integer.

    The number inputs has step size 1 by default. If you want to allow to have a value that requires decimals, you’ll need to reflect this in the step value (e.g. step="0.0001" to allow decimals to four decimal places).

    <form action="?">
    <input type="number" value="123.2423" step="0.0001">
    <input type="submit" value="submit">
    </form>
    Login or Signup to reply.
  2. It is not a bug because whenever you use type="number" browser usually expect number input it can be decimal value.
    Here how it is to be done

    Enter a number:

    Submit

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search