4 ms·
inputmode does localization: > Fractional numeric input keyboard containing the digits and decimal separator for the user's locale (typically . or ,) https://
by brundolf 4y ago
inputmode does localization:
> Fractional numeric input keyboard containing the digits and decimal separator for the user's locale (typically . or ,)
https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inputmode https://developer.mozilla.org/en-US/docs/Web/HTML/Global_att...
As for validation- you can get reasonably far with the `pattern` attribute, but many apps do validation with JavaScript anyway.
The benefit of inputmode is specifically that's it's less opinionated- it lets you give instruction to the system keyboard (which is a feature you can't otherwise provide yourself), but leaves it to you to handle everything else as you see fit.
- runarberg 4y agoOnly on the soft keyboard, not with the value it self. So for users with hardware keyboards it will matter if they type 42.5 or 42,5 (i.e. the browser sees those as different values under different locales). And this becomes an even bigger issue if you use pattern for validation (as you will have to sniff for the user’s locale conditionally adjust the pattern; good luck with that). You also get this and validation error message localized with <input type=number> EDIT: To clarify further. If I type 42,5 on my browser with an Icelandic locale, but your website uses inputmode=decimal, then my input will evaluate as NaN when you run `inputElement.valueAsNumber`. On the other hand you will get 42.5 if you properly set the type=number.
- brundolf 4y agoSure, so that's a good thing to think about when implementing your logic. But it's not like you don't have to think about localization at all if you use type="number", and imo the downsides outweigh the upside of having the browser handle this one case for you
- runarberg 4y agoI feel like you might be underestimating the difficulty of localization. There are way more customary ways to write numbers then you can think of (there is probably a Falsehoods Programmers Believe About Numbers out there which addresses the innumerable ways people write numbers). I also feel like you are underestimating the amount of localization that the browser actually does. Yes you still have to do some localization, but there is a whole issue that the browser does for you if you use the correct attributes. There are way more upsides which you might be unaware of.