-
-
Notifications
You must be signed in to change notification settings - Fork 481
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
Rerun validation on submit #559
Comments
Some additional information:
|
So I have found a way to do this! 🎉 The relevant bits are as follows:
Importantly, this plays nicely with Although this solves my problem, I will leave the issue open in case there's a better/simpler/"more official" way of achieving this. Thanks in advance! 😄 |
I guess I'll reproduce the answer I gave on Stack Overflow... Library author here. I'm always fascinated by new ways people can invalidate my assumptions. I mean that in a sincerely positive way, as it results in learning. 🏁 Final Form makes the assumption that your validation functions are "pure" or "idempotent", i.e. will always return the same result when given the same values. This is why it doesn't run the synchronous validation again (just to double check) before allowing the submission: because it's already stored the results of the last time it ran it. By using an outside timer, you've invalidated that assumption.
No need for mutators or decorators for this problem. The more official way to do this would be to run the check (you could even reuse |
@erikras but will fields be revalidated and show field error messages inside of them? |
Are you submitting a bug report or a feature request?
Feature request
What is the current behavior?
Once a form's fields have been validated, submitting doesn't trigger a rerun of the validation.
What is the expected behavior?
I would like a way to trigger a rerun of the validation when the form is submitted. I have tried using the
beforeSubmit
listener from thefinal-form-submit-listener
package but it only gives access to theFormApi
object. I tried using thepauseValidation
andresumeValidation
functions fromFormApi
but they couldn't achieve what I want, or maybe I'm not using them correctly. I have a feeling it's painfully obvious how to do this, but I can't figure it out. 😩Sandbox Link
See this Sandbox.
What's your environment?
Final form: 4.13.1
React final form: 4.1.0
Other information
I have a form field whose value can become invalid if it's not submitted within a particular timeframe. It's not async; I'm just trying to cover a scenario in which the user doesn't click submit for a while, and when they eventually do, the value would have become invalid. Final form remembers the result of the validation that happens immediately after the value is changed, which means that the unchanged value remains valid regardless of how much time passes between the validation and the submission. This is the behavior I want to hook into and change; the intervening time matters in my use case.
Thanks!
The text was updated successfully, but these errors were encountered: