-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
validateOnChange after submit #1251
Comments
Can you elaborate on this with some use cases and examples? What would the function signature of validateOnChange be? |
Use case is simple — you do not want to disturb user until after the form is submitted at least once. So when the form is submitted at least once this value should be set to true. So there are several possible ways to do this I guess:
I was actually surprised that some of the above it's not available in Formik out-of-the-box. Seems like a basic usability feature to me. Right now I ended up doing this
|
I have also been looking for a way to set validateOnChange and validateOnBlur based on some state of the form without resorting to escape hatches. |
Consider where the user has to check two boxes to agree with something (one for terms and other for privacy policy). With Here's a gif for clarity's sake: My workaround is a variation of @kompot's suggestion (I'm using React Native)
|
Still looking for a way to achieve this easily. Attempted to use const [ shouldValidateOnChange, setShouldValidateOnChange ] = useState(false)
......
validateOnChange={shouldValidateOnChange}
onSubmit={(values) => {
setShouldValidateOnChange(true)
onSubmit(values.text)
}}... |
@thoughtpalette |
Also trying to figure out the best way to do this |
Using the comments above, my solution is the following:
|
Closing due to long inactivity |
Surprised this is not incorporated into the library. I'd say validate once on submit and then on every change is a pretty standard validation strategy. .. No? Would've been nice if My solution, with a wrapper, in case anyone is interested (although the previously posted solutions above are probably more light-weight):
And using the above helper like ... (we have some heavier typings, I just stripped the proprietary stuff, so it's free to share and use -- in case you're wondering about why I'd re-type something that comes straight out of the lib)
|
You can do as follows, worked for me. const [validation , setValidation] = useState(false)
|
Two years, this is still an issue. |
@ybrodsky Can you cite some sources, research or articles about how popular this behavior is? I want it, but I'm not really sure about the UX, or that it is widely used. |
This works for me :) thanks |
I see that that PR with the feature was opened almost 9 months ago. |
🚀 Feature request
Current Behavior
validateOnChange
is either true or falseDesired Behavior
validateOnChange
value can be changed, is not just an initialization config.Suggested Solution
validateOnChange
is a function that has access to the form. Once it's been submitted it validates on change, but not before. (This is what angular does and is quite nice)Who does this impact? Who is this for?
All users
Describe alternatives you've considered
Tried modifying the value
onSubmit
but there's no way to access it. Also thought of hiding the errors until submission but didn't find a way to do so.The text was updated successfully, but these errors were encountered: