https://www.w3.org/TR/html5/forms.html#number-state-(type=nu...
>The type=number state is not appropriate for input that happens to only consist of numbers but isn’t strictly speaking a number. For example, it would be inappropriate for credit card numbers or US postal codes. A simple way of determining whether to use type=number is to consider whether it would make sense for the input control to have a spinbox interface (e.g., with "up" and "down" arrows). Getting a credit card number wrong by 1 in the last digit isn’t a minor mistake, it’s as wrong as getting every digit incorrect. So it would not make sense for the user to select a credit card number using "up" and "down" buttons. When a spinbox interface is not appropriate, type=text is probably the right choice (possibly with a pattern attribute).
A spinbox only makes sense if you don't care what the value is, such that any two nearby values are exactly equivalent. And that is what the W3 guidance you quote says:
> Getting a credit card number wrong by 1 in the last digit isn’t a minor mistake, it’s as wrong as getting every digit incorrect. [And that's why a card number field should not use a spinbox.]
This suggests to me that the real problem is the idea that "type=numeric" means you want a spinbox. You don't ever want a spinbox; there's no reason for any attribute to give you one. But you frequently do want to restrict the input to numeric characters.
Mouse-adjustable low-resolution analog values have their own widget, the scrollbar. If you somehow find yourself wishing for a spinbox, use one of those.
Basically, if "close-ish" is acceptable, then a numeric input makes a ton of sense. And that's the case for lots of things, and most of those things wouldn't be entered with a keyboard (unless you want to get the figure in the ballpark).
If the number is <10 or so most of the time, then a menu makes a ton of sense (number of socks), and include a "custom" option so users can enter their own numbers. I do this with all kinds of things that only need a ballpark number but don't benefit from tweaking (e.g. seconds in an internal; basically, if 10 options or so makes sense, just make it a menu).
I happen to work with graphical things that don't need to be precise much of the time but need more precision that a set of presets. But most retail and whatnot apps are not that.
I agree with that, but this is an attribute of a text entry field. Like I said, we already have a different widget that accommodates the "I don't care what the value is, but I want to be able to easily fudge it upwards or downwards" use case.
Also, input does not necessarily mean text entry. We have <input type=“checkbox”/> and <input type=“button”/> among others.
Some people do like spin boxes, and they allow you to adjust numeric values without reaching for the digit row on your keyboard. By all means, don’t use them if you don’t like them, but they do exist for a reason.
Whether spinboxes are good UI is a separate debate.
If I'm not mistaken, using type="pattern" also means I can't use min or max.
Edit: kibibu below says it's the "inputmode" attribute, but it only works in Chrome currently. :(
https://html.spec.whatwg.org/multipage/interaction.html#inpu...
I agree with another commenter that it would be better if it were called magnitude. Still, even when it's the correct thing to do I still think it's a bad feature because it can be accidentally triggered.
There's a gotcha in Safari when using pattern for zipcodes or anything that can have a leading 0: https://www.filamentgroup.com/lab/type-number.html#support-l...
Yes, you can work around all of these issues by overriding default number behaviour. But some things that look like numbers are really just strings of digits.
The fact that databases use auto-incrementing integers to ensure uniqueness is an implementation detail, and not a strictly necessary one (think UUIDs).
So just because something looks like a number doesn't mean that you can do 'safe' things like add leading zeros.
That looks like a framework-specific issue and if that’s how you process incoming numbers from the Internet, you are clearly doing something wrong.
Anyone on the Internet will reasonably expect that a decimal number provided to a Internet input-field will be interpreted as a decimal number.
Anything else, unless explicitly stated, is by definition an error on the part of the application developer.
https://html.spec.whatwg.org/multipage/interaction.html#inpu...
It'll work in Chrome (and other Blink-based browsers), but nothing else.
Then it isn't the right choice.
1: https://caniuse.com/#search=inputmode
2: https://en.wikipedia.org/wiki/IOS (Latest preview in the infobox)
What's interesting is it used to be partially supported in Firefox, and has now been put behind about:config [0]. I'm curious as to why, since the MDN docs seems to endorse its use. [1]
[0] https://caniuse.com/#search=inputmode
[1] https://developer.mozilla.org/en-US/docs/Web/HTML/Global_att...
If they were numbers, then adding 2 SSNs would have some valid meaning. In reality, adding 2 SSNs is an entirely useless operation.
What they are is basically identifiers who happen to restrict the set of allowable characters to digits.
One consequence of using input type number on a 2 factor verification code box that I have seen is that the browser would eliminate the leading 0. Which is absolutely the correct behavior if the code was indeed a number, but leads to incorrect behavior since it’s not.
I like the article, and have enjoyed everything I've read that Brad Frost has written, but I will probably keep using <input type="number">. I hope somehow this gets back to browser and desktop environment makers and they fix this usability and accessibility issue.