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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to detect aborted form submissions due to validation errors. #2109
Comments
Go for it with PR. We鈥檒l likely debate naming. It I think this makes sense |
Something like this would be really helpful. I don't even need the "fine grained" control. We've had multiple times during development when a form is not submitting and it's a real pain to track down exactly why if our UI is mishandling a field error. Is there already any sort of |
+1 |
+1 |
It would be a million times better (in my opinion) to be able to intercept the events dispatched to Formik like const formik = useFormik(...props);
formik.useIntercept(
React.useCallback(message => {
if (message.type === "SUBMIT_FAILED") {
if (message.reason === "VALIDATION_ERROR") {
toast('something bad happened in validation');
} else if (message.reason === "VALIDATION_FAILED") {
toast(`bad inputs, bad. ${JSON.stringify(message.errors)}`);
} else if (message.reason === "SUBMIT_ERROR") {
toast('something bad happened in submission');
}
}
}, [])
); Although ultimately VALIDATION_ERROR and SUBMIT_ERROR should |
馃殌 Feature request
Current Behavior
When calling
form.submitForm()
it throws if:Desired Behavior
Keep same behavior as current but let user be able to differenciate those different kind of failures with callbacks?
When form.submit() is called, if async validation return errors, I want to be able to emit an error toast/notification/snackbar/whatever
I don't want this toast if it's a validation network error, or if it's the form submission that fails (or if I do I don't want the same message for the toast according to the case)
Suggested Solution
Who does this impact? Who is this for?
For people who need fine-grained form submission error handling logic.
Describe alternatives you've considered
Adding some custom field to the error thrown so that I can catch if and emit different toasts according to the failure situation.
Handling this fine-grained error handling in userland (which requires reimplementing submitForm's logic, so not ideal).
The text was updated successfully, but these errors were encountered: