Skip to content
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

Add userValid to ValidityState #8938

Open
jacobrask opened this issue Feb 23, 2023 · 8 comments
Open

Add userValid to ValidityState #8938

jacobrask opened this issue Feb 23, 2023 · 8 comments
Labels
addition/proposal New features or enhancements topic: forms

Comments

@jacobrask
Copy link

CSS Selectors 4 defines the :user-invalid and :user-valid pseudo classes, that apply to an element after the user has significantly interacted with it [user-pseudos]. :user-invalid and :user-valid were selected for Interop 2023.

These values are currently not exposed by the constraint validation API.

ValidityState.valid matches the state of the :valid selector, but there is nothing for the corresponding :user-valid selector.

When implementing form validation you currently need to keep track of the "touched" status of a form element manually, to avoid showing validation errors before a user has interacted with the form. Adding ValidityState.userValid would let you defer the meaning of "significant user interaction" to the browser and have it be consistent with the behaviour of the :user-valid CSS selector.

@annevk
Copy link
Member

annevk commented Feb 24, 2023

This would require #8452 to be fixed first.

@annevk
Copy link
Member

annevk commented Aug 28, 2023

I don't think this makes sense to be part of ValidityState as all the (absence of) flags there contribute to the meaning of valid, whereas this is not quite that.

@annevk
Copy link
Member

annevk commented Aug 28, 2023

Also, thinking about this more, why wouldn't using matches(":user-valid") be sufficient here?

@jimmyfrasche
Copy link

Maybe it would make sense to separate out the "user has modified it" bit and expose that on the form element itself?

@jacobrask
Copy link
Author

Also, thinking about this more, why wouldn't using matches(":user-valid") be sufficient here?

Couldn't you say the same about HTMLMediaElement.paused and a number of other properties exposed as CSS pseudo classes?

@annevk
Copy link
Member

annevk commented Sep 27, 2023

@jimmyfrasche yeah, #9639 tracks that idea.

@jacobrask you can and sometimes people do. I think we could consider adding userValid as a sibling to validity, but it doesn't fit on ValidityState I think.

@jimmyfrasche
Copy link

@annevk that's for adding a way to set the "user has interacted" but for FACE but I don't see any mention of exposing it on form elements in general.

I think it should just be exposed as userInteracted. You can check that and the validity state easily enough, or use matches, if you want to check :user-{in,}valid but if you wanted to know just whether the elements been interacted with the logic to express that query is more abstruse than necessary.

@annevk
Copy link
Member

annevk commented Sep 27, 2023

That's fair. I guess a boolean getter for that is a reasonable solution as well and simpler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements topic: forms
Development

No branches or pull requests

3 participants