-
Notifications
You must be signed in to change notification settings - Fork 658
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
[selectors] pseudo selector to match forms ValidityState #1525
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') |
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: