Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML input number step without validation

In HTML you can add the step attribute to inputs of type number. I wanted this because I liked how it can simplify the input for the user, by only pressing the up/down key.

I found out that an additional feature of this attribute is, that it forces the user to stay in that interval. HTML does this with validation. You can enter any value manually, but it won't let you submit the form. I don't want this!

To work around with this, I found that there is a novalidate attribute that is used in the <form> tag, which works great. But sadly, the browser support is poor.

I guess I'd need to remove the step attribute and write the functionality by myself with JavaScript/jQuery by triggering the keydown event on it.

like image 365
Cutaraca Avatar asked Jan 07 '17 15:01

Cutaraca


1 Answers

But sadly, the browser support is poor.

That's not true. According to MDN, IE supports the novalidate attribute since version 10, and input[type=number] also since version 10. This means that if a browser supports number inputs, it most likely also supports the novalidate attribute.

like image 127
Michał Perłakowski Avatar answered Oct 28 '22 09:10

Michał Perłakowski