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

input.setCustomValidity() on custom validation failure? #108

Open
jwalton opened this issue Sep 20, 2019 · 1 comment
Open

input.setCustomValidity() on custom validation failure? #108

jwalton opened this issue Sep 20, 2019 · 1 comment
Labels
enhancement Improve existing functionality

Comments

@jwalton
Copy link
Contributor

jwalton commented Sep 20, 2019

Hey, just wondering if you've though about calling input.setCustomValidition(error) to set a custom validation message (around about here)? Is there some reason you're not doing this? Does this have some hidden pitfalls I'm not aware of?

You'd probably want to only do this if a "customValidation" flag was set or something, because if people are using non-strings as errors or string that need to be translated or something, it would be nice for there to be a way to turn it off... Or, maybe have a getCustomValidationMessage() function which returns a string or undefined so people can translate or do whatever on their own?

@wsmd wsmd added the under review The issue is being reviewed by the maintainer label Oct 9, 2019
@wsmd wsmd added the enhancement Improve existing functionality label Oct 19, 2019
@wsmd
Copy link
Owner

wsmd commented Oct 31, 2019

I think this is a great idea, and will make a nice addition to the lib.

It has come up before - see #112

Does this have some hidden pitfalls I'm not aware of?

While trying to answer the question posted there, I realized that the tricky part with custom errors is that we have to clear them as soon as the user starts typing, otherwise the UX could be jarring.

I managed to get around that with current implementation by using validteOnBlur.

For more info: https://codesandbox.io/s/setcustomvalidity-v2ue3

@wsmd wsmd removed the under review The issue is being reviewed by the maintainer label Jan 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improve existing functionality
Projects
None yet
Development

No branches or pull requests

2 participants