Today I Learned - Rocky Kev

TIL about Constraint Validation API (forms)

POSTED ON:

TAGS:

Form inputs are interesting. There's a lot of mechanisms working really hard behind the scenes.

Inputs are pretty powerful. Right out of the box, they can autocomplete, validate data, create minimum/maximum lengths, allow for patterns, and even provide state!

Modern browsers have the ability to check that these constraints are being observed by users, and can warn them when those rules have been breached. This is known as the Constraint Validation API

Right out of the box - this works:

input::placeholder {  color: blue; }
input:invalid { color: red; }
input:valid { color: green; }
input:enabled { color: black; }

Via The Complete Guide to HTML Forms and Constraint Validation


Related TILs

Tagged:

TIL CSRF Attacks

Cross-site Request Forgery (CSRF) is submitting post data from a fake site. To prevent CSRF attacks, web applications should implement measures such as requiring a valid CSRF token to be included with each request, checking the referer header, and using secure cookies.

TIL How to auto-grow textarea with pure css

To do this, you replicate the content of the '<textarea>' in an element that can auto expand height, and match its sizing.Same font, same padding, same margin, same border… everything.

TIL User-facing states