-
Notifications
You must be signed in to change notification settings - Fork 404
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
Use :user-invalid and :user-valid pseudo-classes to indicate visually when client-side validation has failed for an input after user interaction #621
Comments
CodePenNote Codepen Example has validation working for all input types except button, submit, reset, and select multiple types. I might add the select multiple types validation later, but for now its not there. Heres some basic quick css to make this work for :user-valid and :user-invalid input:user-valid,
input:user-invalid {
padding-right: calc(1.5em + .75rem);
background-repeat: no-repeat;
background-position: right calc(.375em + .1875rem) center;
background-size: calc(.75em + .375rem) calc(.75em + .375rem);
}
textarea:user-valid,
textarea:user-invalid {
padding-right: calc(1.5em + .75rem);
background-position: top calc(.375em + .1875rem) right calc(.375em + .1875rem);
background-repeat: no-repeat;
background-size: calc(.75em + .375rem) calc(.75em + .375rem);
}
input:user-invalid,
textarea:user-invalid {
border-color: var(--pico-form-element-invalid-border-color);
background-image: var(--pico-icon-invalid);
}
input:user-valid,
textarea:user-valid {
border-color: var(--pico-form-element-valid-border-color);
background-image: var(--pico-icon-valid);
} And then to add the text after the element you can put a /********** To include a message after the element with info ************/
input:user-valid + small[data-valid]::after,
textarea:user-valid + small[data-valid]::after {
content: attr(data-valid);
color: var(--pico-form-element-valid-border-color);
}
textarea:user-invalid + small[data-invalid]::after,
input:user-invalid + small[data-invalid]::after {
content: attr(data-invalid);
color: var(--pico-form-element-invalid-border-color);
}
input:user-valid + small[data-valid]::after,
input:user-invalid + small[data-invalid]::after,
textarea:user-valid + small[data-valid]::after,
textarea:user-invalid + small[data-invalid]::after {
display:block;
} |
After playing with this some more, I've realized it will take more css to completely ensure the invalid and valid states are correct. |
When I have fought with this in the past, I ended up using CSS to change |
check this out |
Describe the issue
This issue is a follow-on to #47, but proposes the use of
:user-valid
and:user-invalid
pseudo-classes in addition to thearia-*
attributes to apply valid/invalid styles to an input.Current Behavior
Currently, when doing client-side validation using HTML attributes (no JavaScript), an invalid user input entry is not highlighted visually.
Expected Behavior
I would expect client-side validated inputs with which the user has interacted (indicated by the
:user-valid
or:user-invalid
pseudo-classes) to show the proper validation styling.Reproduction URL
https://jsfiddle.net/L2p4rmy1/1/
Environment
As linked above, the necessary pseudo-classes are supported across all major browsers.
The text was updated successfully, but these errors were encountered: