[whatwg] Idea: pseudo-classes :valid and :invalid for whole form?
Eduard Pascual
herenvardo at gmail.com
Wed Jun 15 12:12:24 PDT 2011
2011/6/15 Boris Zbarsky <bzbarsky at mit.edu>:
> No, it wouldn't. The point here is to style based on a _form_ that is
> invalid. Whether a form is valid or not is up to the language defining
> forms, that being HTML.
Sorry, I assumed the simple definition that a form is invalid if it
contains invalid input elements, and there are proposals on the wiki
to deal with selecting an element based on its children.
Of course, something like form:invalid { ... } would be ideal, but a
syntax like $form :invalid { ... } wouldn't be too bad.
I missed the possibility of a validation script (onsubmit event
handler) making more complex checks (like "if first field is X, then
the second field can be anything but "Y""). However, there is no clean
way to deal with those cases short of adding onchange handlers on all
inputs:
- If a browser attempts to run the onsubmit handler upon each change,
to update the style of the form as soon as it becomes (in)valid, then
there is a risk of the javascript having some side-effect that is not
intended to happen on each change.
- If a browser waits for a submit attempt, this can easily become
confusing to users (the change in style should be triggered by the
change that actually made the form invalid). That would partially
depend on the actual style applied; but it could be easily implemented
by the document author with a single javascript line (adding a class
or some other attribute to the form), so the feature would be a sort
of glorified syntax sugar.
Maybe a sort of compromise would be implemented: checking for invalid
individual elements and, if the onsubmit handler is known to not
trigger side-effects, check it as well. But this sounds more like a
hack.
Is there something I am missing?
Regards,
Eduard Pascual
More information about the whatwg
mailing list