-
Notifications
You must be signed in to change notification settings - Fork 717
[selectors] pseudo selector to match forms ValidityState #1525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is covered by the Sebastian |
the |
I see. And you're right, there doesn't seem to be more fine-grained matching of invalidity except the Note that CSS uses hyphen-separated syntax, not camel case. So, your proposal should rather look like this: input:value-missing ~ .required { display: block; }
input:too-short ~ .minlength { display: block; }
input:too-long ~ .maxlength { display: block; }
input:pattern-mismatch ~ .pattern { display: block; } Another way would be to allow parameters for the input:invalid(value-missing) ~ .required { display: block; }
input:invalid(too-short) ~ .minlength { display: block; }
input:invalid(too-long) ~ .maxlength { display: block; }
input:invalid(pattern-mismatch) ~ .pattern { display: block; }
input:invalid(out-of-range) ~ .outofrange { display: block; } which would allow to match different types of errors by allowing to provide multiple keywords: input:invalid(too-short, too-long) ~ .invalidlength { display: block; } Furthermore, for empty inputs there is already issue #1283. So empty inputs requiring a value could then also be matched via Sebastian |
Like the idea! Which we had came up with parameters for the It seems like this idea of parameters is also better feature wise if we decide to add new validity properties in the feature... |
Just for the shake of it i wrote a jQuery.expr $.extend($.expr[':'], {
validity: (node, i, args) =>
args[3]
.replace(/-([a-z])/g, g => g[1].toUpperCase())
.split(',')
.some(prop => node.validity[prop.trim()])
}) $('input:validity(value-missing)').css('color', 'red') |
I think the above proposals of either making invalid functional (along with user-invalid) or adding new pseudo classes is a good idea and is a step towards improving styling of form control errors based on validation state. :value-missing is probably covered by the existing proposed :blank psuedo combined with :required but could be nice to include for completeness. Instead of invalid(out-of-range) we could potentially do below-range and above-range to offer even more granularity? |
I find this suggestion useful. Currently, we have the A set of selectors might look as follows (presented in the table):
A combination of the A set of these selectors would enable the addition of hidden error messages that can be displayed without the need for JavaScript. This approach can be useful for basic form validation and progressive enhancement. |
The special cases of |
Uh oh!
There was an error while loading. Please reload this page.
The Problem
When I did put a pattern to one of my form elment, it yields a tooltip saying "Enter a correct pattern"
The browser don't do a good job at displaying the correct pattern to use. So i need a way to inform them how the field should be written (look like)
The solution
I would want it to behave a little like angular´s ngMessage, see demo
Say you got custom errors like this:
Now to style the right error message green or red, show or hide. I would want to use the same properties that exist on the constraints object
input.validity
(ValidityState)The text was updated successfully, but these errors were encountered: