Post

you can use CSS to detect not only when a form is :valid but also when it's been interacted with s/:valid/:user-valid 🤙 .group:has(:user-invalid) { --color: var(--invalid); } input:user-invalid + .error { display: block; }

Helge Ahrens@tylopilus.bsky.social

@jhey.dev I have read somewhere how to create custom validation messages of form fields without js. Do you have a reference at hand?

6 reposts163 likes

Love it, thank you for this. I was blanking on user-valid. All I remembered was that invalid always checked even when the user has not interacted with it. This is what I was looking for!

was a great opportunity to take it for a spin again 🙏 last time i posted about it, it wasn't fully supported yet but now we should be good to use it freely 🚀

good reference but also still leaves people thinking "right, so what do I do?" arguably - using CSS for purely visual aesthetic poses no issues. we shouldn't rely on color anyway updating aria-invalid on submit would be a "take away" here and that there isn't a clear route on where to put messages

Oh I agree. It's one of the most frustrating part of these things. "Okay...so what is the right answer" "There is none. You need user testing, and manual testing" Isn't exactly a fun answer to get :/ And then each browser behaving differently provides some extra 🪄 razzle dazzle 🪄

i'd go for it with styles in a progressively enhanced way the number of unsupported users is perhaps ~5% across "popular" browsers there but for those without support, are they going to miss/care if the input doesn't change color?

the error message part could be handled differently but you'll need JavaScript anyway in order to update any appropriate aria-* attributes on submit that said, i am still not 100% on this because with forms where we don't use client scripting, do we just not bother with dynamic messaging