News for hackers. Stuff that matters.
Re:The number input is the worst input by runarberg on Thursday September 15, 2022 @07:10PM (#32859669)
This advice sounds awful lot like the old school “don’t use <table>”.

It is a terrible advice, you shouldn’t use <table> for styling, but if you are representing a tabular data, by all means use <table>. I’ve heard some developers (mostly back end devs that dabble in front end) say you’re not supposed to use tables, and I’ve seen div soups where there definitely should be tables. And I blame overuse of the rhetoric “don’t use <table>”.

By all means, if your taking in a numeric value, use <input type=number>. You get frontend validation, localization, context aware soft-keyboard, accessibility etc. all for free. Use it.

If however, you don’t have a numeric value (e.g. a value that is simply represented with digits) use something else. In general, if ordering values makes sense, then most likely <input type=number> is your best choice.

Re:The number input is the worst input by IlliOnato on Friday September 16, 2022 @02:22AM (#32862759)
Hmm. The author's problem is not with <input type=number> conceptually, which would be fine if properly supported by browsers, i.e. in the ideal world.

In the real world, however, the browsers apparently a) don't prevent users from entering incorrect values b) don't allow the developer to do anything about it programmatically, by preventing access to these incorrect values (always returning empty).

The author brings attention to this problem.

Now it's up to you as a developer to decide whether the benefits of using <input type=number> outweigh the costs, but the costs are real and you need to be aware of them.

Re:The number input is the worst input by runarberg on Friday September 16, 2022 @01:00PM (#32868964)
It is supported by all modern browsers. Even IE-11 supports valueAsNumber and the most important Constraint Validation API methods to deal with the problems the author mentions.

If you want to deal with inconsistent (and possible eccentric) user input: Use input.valueAsNumber

If you want to distinguish between empty and invalid inputs: Use input.validity.valid or input.validity.badInput

If you want to programmatically deal with incorrect entries: Again use the constraint validation API.