News for hackers. Stuff that matters.
Re:HTML Form Validation is heavily underused by nikeee on Monday October 28, 2024 @08:16PM (#41978038)
I avoid the use of `type=number` and use `type=text inputmode=numeric` instead. It doesn't come with these arrow buttons which most users don't need anyway for entering numbers. Also the keyboard is better on iOS.
Re:HTML Form Validation is heavily underused by ryncewynd on Monday October 28, 2024 @08:47PM (#41978227)
Thanks for the tip wasn't aware of that.

I rarely want those arrow buttons for numbers

Re:HTML Form Validation is heavily underused by mananaysiempre on Monday October 28, 2024 @09:17PM (#41978393)
> these arrow buttons

A spinner control, that is.

Spinners always puzzled me, to be honest. There is obviously a need for a compact numeric input control that both displays the exact value and allows rough changes using the mouse. Witness knobs in DAWs—which don’t actually work the way you’d expect from their appearance, you’re supposed to grab and then drag in a linear fashion, possibly ending outside the knob’s screen bounds. Or consider the weird input thing Darktable uses—which at least doesn’t mislead you with false skeuomorphism, but takes a bit to figure out. Then there are the inputs used for color grading in DaVinci Resolve. And so on. And all of them are nonobvious. Spinners are obvious, but they are also needlessly fiddly to use with the mouse, and neither do they provide the at-a-glance readability of knobs et al.

I feel like humanity just hasn’t solved compact numeric inputs yet.

Re:HTML Form Validation is heavily underused by lelanthran on Monday October 28, 2024 @10:50PM (#41978888)
> Spinners are obvious, but they are also needlessly fiddly to use with the mouse

I think that a quick improvement would be to let the mouse wheel "spin" the number up/down when the input element is focused.

An even better improvement would be having the `<input type='range'>` element actually display the value as it changed, and allow the user to set that value directly (say, by typing it in).

Right now, range is useless because the user cannot tell what is selected. The developer has to add in extra JS magic to let the user set range to an exact value, or to show the user the value they have chosen.

If `range` is improved in this way, then spinners are redundant and can be ignored.

Re:HTML Form Validation is heavily underused by LegionMammal978 on Monday October 28, 2024 @11:23PM (#41979073)
> I think that a quick improvement would be to let the mouse wheel "spin" the number up/down when the input element is focused.

Firefox did that for number inputs for a long time, until very recently. They switched it off in Firefox 130 because people kept inadvertently changing values in forms while scrolling through them [0]. Personally, I've set the about:config option to reenable it since I've found it useful in certain interfaces, though I can't imagine it's much longer for this world.

[0] https://bugzilla.mozilla.org/show_bug.cgi?id=1741469

Re:HTML Form Validation is heavily underused by account42 on Tuesday October 29, 2024 @06:41AM (#41982294)
Isn't this same issue already solved for other scrollable elements? Scroll should only affect the individual element if the mouse was over that element when you started scrolling.

I guess the room for unwanted consequences is a bit bigger when the scrolling controlls the value instead of just the viewport.

Re:HTML Form Validation is heavily underused by LegionMammal978 on Tuesday October 29, 2024 @04:18PM (#41988887)
That is how it worked, but people still found it problematic. E.g., from one of the comments on the issue:

> In step (3) here, if you do several mousewheel-spins while also subtly moving the mouse (just from placing your hand on it), it's quite easy/possible for the first spin to inadvertently change the value that you just entered (since step 1 had left the cursor hovering the input field, so that's where it starts), and then for the subsequent mousewheel-spins to successfully scroll the page. This can mean you change the number you just entered without noticing (and also without it being "in the middle of an existing scroll action", hence my note that this suggested mitigation wouldn't necessarily help).

The cause being that people don't look at where their cursor is before they start scrolling, and don't look at the value since they've finished entering it.

Re:HTML Form Validation is heavily underused by mjevans on Tuesday October 29, 2024 @04:25PM (#41988964)
That's almost correct. I generally agree with hover == focus as a Window Manager level thing, but for document inputs within an application I still prefer required user interaction to set the focus location. E.G. a click, a tab, just move the line forward.

The correct context model is to not select an element for scrolling until it has been made the active element, and that UI element SHOULD have some sort of embellishment to make it obvious that's the focus.

Re:HTML Form Validation is heavily underused by francislavoie on Tuesday October 29, 2024 @01:49AM (#41979756)
But what's crazy is both of those still don't disallow non-numeric input unless you use JS to reject keystrokes and intercept paste. HTML form validation is so incomplete and limited, every time I look at it I want to scream cause wtf there's so many just totally obvious things we need that don't exist by default and we need to reinvent the wheel. Native date and time inputs are still garbage so every UI framework has to build their own solution.
Re:HTML Form Validation is heavily underused by Dwedit on Tuesday October 29, 2024 @02:36AM (#41980041)
I used to write those fancy textboxes that reformatted your input as a phone number as you type, and intercept paste, and all that.

But then it turns out that you really do want a free-form text input. Let people paste text in, edit their text freely, then let it validate afterwards. When it validates, then reformat it.

For example, text boxes with length limits. These are awful. It messes with your ability to paste something in, then edit it down to the correct length.

Re:HTML Form Validation is heavily underused by francislavoie on Tuesday October 29, 2024 @02:45AM (#41980091)
Nah. Users are too stupid to fix their own inputs in many cases. Seen inputs with zero-width spaces that are invisible which fail validation. User doesn't understand why, complains. Enforcing a character set for certain kinds of inputs is a very good thing.
Re:HTML Form Validation is heavily underused by onion2k on Tuesday October 29, 2024 @03:03AM (#41980173)
In 26 years of web dev, mostly as a frontend person, I've only seen zero width spaces in three situations

- pasting from Word

- QA testers being through

- devs pranking each other

The third one is by far the most common. Word is much better these days and I've not seen that happen in a long time. I wish I saw QA test this stuff more often. The idea that it's common enough that you'd break your UX to handle it baffling to me.

Re:HTML Form Validation is heavily underused by francislavoie on Tuesday October 29, 2024 @03:08AM (#41980211)
"Break your UX" is a vast exaggeration. I'm not talking about phone number fields, to be clear. I'm talking about like numeric amounts, with maybe a negative or decimal point. It's literally just [0-9\.-] but that still requires JS to limit inputs to that.
Re:HTML Form Validation is heavily underused by HappMacDonald on Tuesday October 29, 2024 @07:54AM (#41982943)
What's wrong with

<input type="text" pattern="[0-9.-]*">

though?

Re:HTML Form Validation is heavily underused by francislavoie on Tuesday October 29, 2024 @08:15AM (#41983092)
It doesn't prevent the bad input, it only validates it on submission.
Re:HTML Form Validation is heavily underused by jcelerier on Tuesday October 29, 2024 @05:27AM (#41981327)
I see weird spaces every time I copy-paste from some pdf pretty much, especially if it's a digitised or 10+ years one. Hardly an irrelevant use case
Re:HTML Form Validation is heavily underused by lomase on Tuesday October 29, 2024 @06:19AM (#41982058)
Add to that pasting from MS Teams.
Re:HTML Form Validation is heavily underused by ragnese on Tuesday October 29, 2024 @07:54AM (#41982940)
I'll be one of those guys. I see the invisible whitespace from pasting ALL the time. I've literally dealt with user complaints caused by it three times in the last two weeks! (Usually customer issues don't make it to me unless our support team can't figure it out or suspects a bug)

To be fair, it's not usually that frequent. Just a funny coincidence that I've JUST dealt with it more recently.

Re:HTML Form Validation is heavily underused by 71bw on Wednesday October 30, 2024 @04:00AM (#41992772)
Try copying any string from any e-mail.
Re:HTML Form Validation is heavily underused by pmontra on Tuesday October 29, 2024 @03:06AM (#41980192)
The problem here is that sometimes users and copy pasting from another document and that comes in arbitrary formatting, not the one enforced by the input element.

For example phone numbers can be a string of digits, or multiple strings separated by spaces or hyphens or with parts enclosed by () etc

It's a more pleasant UX to let them paste anything, then edit it inside the input, validate and submit.

Re:HTML Form Validation is heavily underused by xigoi on Tuesday October 29, 2024 @03:18AM (#41980280)
> For example phone numbers can be a string of digits, or multiple strings separated by spaces or hyphens or with parts enclosed by () etc > > It's a more pleasant UX to let them paste anything, then edit it inside the input, validate and submit.

How is that more pleasant than a textbox which automatically removes the extra characters?

Re:HTML Form Validation is heavily underused by djtango on Tuesday October 29, 2024 @04:41AM (#41980973)
Because you don't know what your user wants to do and eventually you'll annoy someone
Re:HTML Form Validation is heavily underused by kevincox on Tuesday October 29, 2024 @09:28AM (#41983649)
What if I copy something but accidentally get another couple words one of which is a number. For example copying from a chat app and get the date with the message. Then my "Sep 24th 416-555-1234" input which, would have been very easy to fix, becomes 244-165-5512 34. It will take me a few seconds to realize what has happened, identify where the intended phone number starts and remove the accidentally pasted digits.

The nice thing about the native input is that it is very simple, predictable and flexible. It may be easier to make a better UX on the happy cases but it is very difficult to not add some suboptimal and confusing UX on the less happy cases. Often times it is best just to keep it simple so that the user can easily complete their task rather than adding some "magic" which may backfire and confuse users.

It is surprisingly often that I need to open a text-editor or clipboard-editor to format values before pasting them into apps or websites because they have broken an input field by trying to be magic and failing to consider anything but the happy cases and maybe one or two bad paths.

Re:HTML Form Validation is heavily underused by francislavoie on Tuesday October 29, 2024 @09:33AM (#41983687)
I was talking about numerical amount fields, not phone numbers or dates or credit card numbers. Those are different things entirely.

FWIW if you're copying text on Android, you can tap the clipboard popup to edit the clipboard item before pasting it elsewhere.

Re:HTML Form Validation is heavily underused by kevincox on Tuesday October 29, 2024 @09:41AM (#41983753)
The exact same problem applies. If I copy "Sep 24 $2412.45" out of a message and you quickly "clean" it to 242 412.45 I may not notice and even if I do it will take a second for me to realize what happened and clean up the value to be the intended amount. If I see the original text in the field it is much more obvious what happened and quicker for me to understand what I need to do to fix it.
Re:HTML Form Validation is heavily underused by pmontra on Wednesday October 30, 2024 @01:28PM (#41997875)
> FWIW if you're copying text on Android, you can tap the clipboard popup to edit the clipboard item before pasting it elsewhere.

I never noticed that after 13 years of Android. I checked that now and I could not find a way to do it. Samsung's keyboard has a way to look at the clipboard but I could not edit them. Swiftkey does not. Maybe Google's keyboard? It's not on my phone. I looked at a couple of videos but they don't look anywhere like my phone. Not a feature to invest much time on it. If I have to edit the clipboard and I can't do it where I want to paste it, I open an editor and paste it there.

Re:HTML Form Validation is heavily underused by francislavoie on Wednesday October 30, 2024 @02:07PM (#41998344)
I'm using stock Android, Pixel 8 Pro. Highlight text then tap "Copy". See a toast in the bottom left. Tap on it (not the X) and a little text editor applet opens up. Here you can edit the text and save it, updating the value in the clipboard. Then using Gboard, it has clipboard history so you can see and paste the specific recent item from the past hour that you want. (Unfortunately it can't be edited after initially copying although you can long press them in the Gboard menu to pin for longer or delete them).
Re:HTML Form Validation is heavily underused by eru on Tuesday October 29, 2024 @03:33AM (#41980391)
Why blame it on the user, instead of fixing it?

You could remove the zero-width spaces in validation (for eg a phone number).

Re:HTML Form Validation is heavily underused by francislavoie on Tuesday October 29, 2024 @03:36AM (#41980406)
Or, you know, prevent invalid characters from the get-go. Same thing as validation, but done up-front. (But as I said elsewhere, I'm not talking about phone numbers, I'm talking about amounts)
Re:HTML Form Validation is heavily underused by eru on Tuesday October 29, 2024 @03:43AM (#41980453)
I would like to allow people to copy-and-paste text in, and then edit it. That could be a longer text that has the amount in it (but also some unrelated numbers).
Re:HTML Form Validation is heavily underused by yakshaving_jgt on Tuesday October 29, 2024 @06:40AM (#41982287)
Because this often makes the input feel broken to the user.

Instead of asserting that "users are too stupid" as you have done earlier, perhaps programmers should be less stupid and write more permissive parsers.

Accessible design is actually pretty hard, and most designers and programmers get this wrong. If you want some good design advice, you can start here: https://adamsilver.io/blog/the-problem-with-live-validation-...

Re:HTML Form Validation is heavily underused by francislavoie on Tuesday October 29, 2024 @09:31AM (#41983671)
I'm not using "stupid" in the derogatory sense. I'm using it as a recognition of the skill/knowledge gap between technical and non-technical users.

To clarify, we get _asked_ by our users to implement fields that limit input to help them avoid mistakes. Our QA and UX teams agree. This isn't a unilateral engineering decision.

Re:HTML Form Validation is heavily underused by eru on Tuesday October 29, 2024 @08:58PM (#41990980)
Yes, you want to provide guidance, but without getting in the way.

That's why I was suggesting letting the user paste in these 'wrong' characters, but offering help in removing them.

Of course, that's a trade-off. And it's more annoying to design and implement than just forbidding those characters from entering the input field in the first place.

Re:HTML Form Validation is heavily underused by hluska on Tuesday October 29, 2024 @07:16AM (#41982690)
I’ve read some very user hostile things in my career, but this one is particularly acerbic. It’s a bad look.

If I ever grew to hate users this much, I would find a new career. You should consider that.

Re:HTML Form Validation is heavily underused by francislavoie on Tuesday October 29, 2024 @08:17AM (#41983102)
I'm not being user hostile. I'm being cognizant that the skill levels of users is extremely wide, and to best serve everyone from a UX standpoint, it's best to limit the characters accepted in the input. It protects the user, helps them avoid mistakes.
Re:HTML Form Validation is heavily underused by hluska on Tuesday October 29, 2024 @12:07PM (#41985688)
> Users are too stupid.

That is the definition of user hostile. Why lie? You make yourself and your organization look bad.

Re:HTML Form Validation is heavily underused by AnimalMuppet on Tuesday October 29, 2024 @12:20PM (#41985916)
Not everyone who disagrees with you is lying. Accusing people is a bad look here on HN. "Assume good faith" is the standard.

You can say "You're wrong". "You're lying", though, is almost never appropriate, and is, in itself, quite hostile.

Re:HTML Form Validation is heavily underused by hluska on Tuesday October 29, 2024 @01:04PM (#41986655)
Again “users are too stupid”. That’s remarkably hostile to users and doesn’t belong.
Re:HTML Form Validation is heavily underused by francislavoie on Tuesday October 29, 2024 @01:53PM (#41987433)
Please read my other comments. I'm not using "stupid" in the derogatory sense. I'm using it as a recognition of the skill/knowledge gap between technical and non-technical users.
Re:HTML Form Validation is heavily underused by AnimalMuppet on Tuesday October 29, 2024 @01:39PM (#41987246)
Fine. But "you're lying" is also hostile, and also doesn't belong.

(I see that you edited that bit out of your post, so thanks for listening...)

Re:HTML Form Validation is heavily underused by guappa on Tuesday October 29, 2024 @08:36AM (#41983239)
From reading your comments, you're extremely user hostile and I hope to not come across anything you work on because they are the very definition of antipatterns
Re:HTML Form Validation is heavily underused by francislavoie on Tuesday October 29, 2024 @08:43AM (#41983280)
It's a decimal number field. There's no reason to have any other characters than [0-9\.-]* You're overreacting. You're attacking me for no reason.
Re:HTML Form Validation is heavily underused by guappa on Tuesday October 29, 2024 @09:50AM (#41983826)
Except if one copied it and it has a space in the beginning and your amazing script won't let one paste it.
Re:HTML Form Validation is heavily underused by kevincox on Tuesday October 29, 2024 @09:21AM (#41983594)
In most cases when you are accepting a numeric value it is best to just strip anything that isn't 0-9 then run validation on just the digits. There are some exceptions like phone numbers which may need + prefixes and similar but you can adjust these rules.

What I have found to work well is when the user unfocuses the input field or on submit strip everything but expected values then validate. If you want you can format the value at this time too (and the formatting won't interfere with text input).

If you want to get really fancy you can strip and format as they type and be careful to keep the formatting "virtual" such that the user is only editing the raw digits but this is very tricky to get right on all platforms and support all expected native editing UX. But even in the best cases this can have bad edge cases. For example the user pastes some text but it happens to have multiple numbers in it, if you eagerly strip and format what is left for the user will be these two numbers mushed together with misplaced separators or similar. If you let them paste, remove the unintended stuff, then format on blur this just works and is understandable.

Re:HTML Form Validation is heavily underused by Groxx on Tuesday October 29, 2024 @04:11PM (#41988806)
Very much this. Live re-structuring runs afoul of tons of things you can't predict.

You can validate roughly anywhere, but at the absolute earliest, only re-format on blur. Never earlier. You have no idea what the user might be doing in the meantime.

And even then, I'd strongly suggest not changing what they entered. Change it to a display-only element with nice formatting if you want, but don't screw with their input.

Re:HTML Form Validation is heavily underused by wodenokoto on Tuesday October 29, 2024 @04:28AM (#41980891)
> what's crazy is both of those still don't disallow non-numeric input

Which is really nice for copy pasting. For example, I have a number with spaces in it, and when I paste I get nothing or only until the first space because someone decided I'm not allowed to have non-numericals in the input field at anytime.

Re:HTML Form Validation is heavily underused by account42 on Tuesday October 29, 2024 @05:15AM (#41981245)
You shouldn't reject keystrokes as that can lead to silent errors when the user thinks they entered something that was not allowed.

And final validation needs to happen on the server side anyway - anything before that is just a usability helper.

Re:HTML Form Validation is heavily underused by joelanman on Tuesday October 29, 2024 @08:32AM (#41983214)
exactly. Silently refusing input is an anti-pattern
Re:HTML Form Validation is heavily underused by user3939382 on Tuesday October 29, 2024 @07:22AM (#41982722)
And yet in both cases the browser insanely casts the data type to string when reading the value.
Re:HTML Form Validation is heavily underused by silvestrov on Tuesday October 29, 2024 @10:02AM (#41983940)
I think type=number is a mistake as it is too generic. It is difficult to get proper validation, UI and error messages.

It should be split into:

type=integer so the keyboard does not allow anything besides 0-9

type=decimal so the keyboard also allows decimal dot/comma and a fixed number of decimals!

type=float which allows for scientific notation, e.g. 1.2e42