You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If onSubmit() is defined as a synchronous function, then any time an exception occurs within submission execution will cause the isSubmitting state to stay true.
Expected behavior
isSubmitting is set to false after an error occurs during onSubmit() execution.
In the sandbox I linked, fill out the email form, though not required
click submit (i defined the onSubmit() function to throw an error rather than show alert, and it's synchronous)
Observe the props in the json printout shows "isSubmitting": true and the submit and refresh buttons are still disabled. Changing the form doesn't reset them
Suggested solution(s)
See expected behavior section.
Additional context
This has proved to be a problem for me because I need to use some non-async calls for my form submission which use the .then() promise callbacks. Because my submission buttons disable if isSubmitting is true, they stay disabled.
Your environment
Software
Version(s)
Formik
2.2.5
React
16.11.0
TypeScript
3.8.3
Browser
n/a
npm/Yarn
n/a
Operating System
n/a
The text was updated successfully, but these errors were encountered:
I have changed my code to use async submissions to resolve this issue on my end, but wanted to ask if there is any future work to make synchronous submissions set isSubmitting to false after finishing? it might mean fewer conditionals users have to bake into their own code and perhaps a bit of a re-render performance boost.
@mryanlo we don't want to assume that isSubmitting should be false after a sync callback because there is no way to tell whether the dev used asynchronous code in a fire-and-forget format. Examples are functions like setTImeout which don't return a Promise.
We should probably have forced users to wrap code like this in a Promise from the beginning and setSubmitting(false) automatically after sync code, but this didn't make too much sense when Promises were less ubiquitous and I don't think it makes sense to do this now, when there's probably so much code out there that works without this limitation.
Bug report
Current Behavior
If
onSubmit()
is defined as a synchronous function, then any time an exception occurs within submission execution will cause theisSubmitting
state to stay true.Expected behavior
isSubmitting
is set to false after an error occurs duringonSubmit()
execution.Reproducible example
Code sandbox: https://codesandbox.io/s/formik-issubmitting-error-example-k0fwd
"isSubmitting": true
and the submit and refresh buttons are still disabled. Changing the form doesn't reset themSuggested solution(s)
See expected behavior section.
Additional context
This has proved to be a problem for me because I need to use some non-async calls for my form submission which use the .then() promise callbacks. Because my submission buttons disable if isSubmitting is true, they stay disabled.
Your environment
The text was updated successfully, but these errors were encountered: