Live data from Hacker News

HTML Form Validation is underused

expressionstatement.com

141–150 of 343 posts

Re: HTML Form Validation is underused

#141
post #116

The best native HTML validation is server-side validation. The only downside: the user has to wait 300ms.

Assuming the actual validation of form input takes ~1ms, this is a fairly unusual amount of latency to experience in 2024.

You've got tech stacks and cloud services that will put you within 20ms of 99% of your users.

Server side everything is still the safest possible bet you can make.

Re: HTML Form Validation is underused

#142
post #22

In an all honest reply, is that the people that writes these specifications, live disconnected from the reality, they don't use the stuff they specify. That stuff works for very simple things, but then when your forms evolve you realise you will be better off just writing the whole thing yourself.

Most of the forms features are from the early 90s. You're not working in the same millennium as some of the specification writers.

The `required` attribute, which this article is about, is an HTML5 thing and first appeared in browsers in 2010-2011. So sure, not brand spanking new, but the web was already used to write modern apps. There's no good reason for the validation features to be so shabby.

Re: HTML Form Validation is underused

#144
post #125
post #118

Earlier quoted context omitted.

On Android, the date picker widget is fiddly to use for selecting distant dates, like date of birth. Not impossible but requires many many taps.

That's an implementation issue, not a specification issue. The specification just suggests the user is shown a date picker.

It doesn't really matter whose fault it is, the end result is that your users have bad experience on your website.

Re: HTML Form Validation is underused

#145
post #31

Earlier quoted context omitted.

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.

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 ha…

> 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 underused

#146
post #130

Earlier quoted context omitted.

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.

> 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?

Because you don't know what your user wants to do and eventually you'll annoy someone

Re: HTML Form Validation is underused

#147
post #11

The biggest, easiest to implement underutilization is: "Using specific type attribute values, such as "email", "number", or "url"" These can significantly improve user experience on mobile by triggering the optimal keyboard.

I found this very extended with "date" input. It seems that every single frontend library has its own date widgets, and lots of them look awful in small screens. You have to add a JS and CSS just for that widget, some depending on jQuery. True, some of them are very configurable, but with the tiny cost of " " you have a widget that looks decent and native everywhere, probably cover your needs, and you can forget abou…

A lot of those date and time pickers will fail WCAG testing as well.

In most cases, GDS now use just 3 text fields for day, month and year, but recommend pickers for dates close to today's date e.g. for booking an appointment, because a picker is easier if you don't know the exact date without reference to a calendar.

Sadly they don't currently have a recommended picker, but there's a useful discussion of what has been tried here:

https://github.com/alphagov/govuk-design-system/discussions/...

Re: HTML Form Validation is underused

#148
post #11

The biggest, easiest to implement underutilization is: "Using specific type attribute values, such as "email", "number", or "url"" These can significantly improve user experience on mobile by triggering the optimal keyboard.

I found this very extended with "date" input. It seems that every single frontend library has its own date widgets, and lots of them look awful in small screens. You have to add a JS and CSS just for that widget, some depending on jQuery. True, some of them are very configurable, but with the tiny cost of " " you have a widget that looks decent and native everywhere, probably cover your needs, and you can forget abou…

The native date input is terrible. Not the actual native control, which is usually okay, but the field itself. You can't even format the date! That's the number one reason I always use some datepicker library in combination with a regular text input.

Re: HTML Form Validation is underused

#149
post #123

Earlier quoted context omitted.

This is particularly annoying on mobile since on-screen keyboards won't adjust to an email input layout and autocorrect will screw up basically any email address as soon as a "." character triggers autocomplete to commit it's guess.

And password managers will not fill in the credentials correctly.

Get a better password manager? I use Bitwarden and it has never failed to fill out the login forms for me.

Re: HTML Form Validation is underused

#150
The last example is bad. You shouldn't scream at your users before they even had a chance to enter the required information so the second password field should not be marked red until the user either is done entering text there (onblur) or tries to submit the form.
Post reply on HN