-
-
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
setSubmitting not working #1957
Comments
Experiencing a similar issue. |
same problem |
I first thought that my form has some issues. After debugging I can say that |
true, need to create for example promise or async and await for response submit, Full example |
I'm also experiencing this issue. the docs say when you call |
It appears from the source that the submit handler is now expecting a Is this the new API of V2? |
I am now returning my promise handler and its now working, but I dont like this approach, because if you have chain promises, then |
Can someone fix this or change the documentation, please? This is basic functionality for most forms and I went almost insane trying to figure out what was wrong 馃槄 |
It's a bit unclear which behaviour is the intended one for version 2. If we can get some clarification I'd be happy to create a pull request. |
@Tigge For what it's worth, my vote would be to duplicate as closely as possible the behavior of Version 1, since I believe this would alleviate the need to refactor code to address this issue and in turn make migration to Version 2 as seamless as possible. Just as an example, I have been using isSubmitting in my fields and buttons to disable functionality. |
You should need to return a promise I thought. Manual setSubmitting calls should still work (mimic v1 behavior) |
@jaredpalmer: Previous behaviour is here https://github.com/jaredpalmer/formik/blob/version-1.5.8/src/Formik.tsx#L444. Nothing in formik touched the
In version 2 the behaviour is here https://github.com/jaredpalmer/formik/blob/master/src/Formik.tsx#L713, once your I agree with @kbi-daniel that following version 1 behaviour would be nice - at least if you want to make the transitioning easier. If not - at least one of rejecting or resolving should keep the |
Also the onSubmit function is typed as |
And it's also very annoying when you expect an async result from a Redux state. Please allow us to disable this new behaviour of isSubmitting and allow us to use setSubmitting again. |
In version 2 the behaviour of isSubmitting was changed from having the user handle it's state after submitting to always resetting it to false after the onSubmit handler had returned (or it's promise). This reverts it back to the version 1 behaviour of not touching the isSubmitting state after the onSubmit handler has been called. Solves: jaredpalmer#1957
In version 2 the behaviour of isSubmitting was changed from having the user handle its state after submitting to always resetting it to false after the onSubmit handler had returned (or it's promise). This reverts it back to the version 1 behaviour of not touching the isSubmitting state after the onSubmit handler has been called. Solves: jaredpalmer#1957
I've created a pull request (#1987) to revert the behaviour to how it functioned in version 1. If we want some other behaviour I'd be happy to adjust it or create a new pull request. |
It will introduce a subtle bug that user can still click the button when you direct user to another page after the promise is fulfilled. const onSubmit = (...) => {
return submit(...).then(() => {
Router.push(...) // The button is already enabled so user can click the button again.
})
} |
In version 2 the behaviour of isSubmitting was changed from having the user handle its state after submitting to always resetting it to false after the onSubmit handler had returned (or it's promise). This reverts it back to the version 1 behaviour of not touching the isSubmitting state after the onSubmit handler has been called. Solves: jaredpalmer#1957
I'm seeing this issue in v2 as well. I see there's a PR to change it back to v1 behavior which I support. |
Yeah I've also face the same issue in my latest project where I install the |
Same here. I've switched back to |
This got me too. Perhaps a way of making both approaches (old + new) work is to check if the submit handler returns a promise, and only then trigger the new behavior. I'm using redux saga to handle side effects so my method returns immediately after dispatching my actions and later on as part of my saga I'd |
This was confusing as well. I think the doc should at least be updated to indicate a Promise needs to be returned for it to work as indicated. |
This is ideal and easy to implement. Can someone open a PR? |
@jaredpalmer but should there not be a way to keep the form in an unsubmitted state in the new promise version? |
In version 2 the behaviour of isSubmitting was changed from having the user handle its state after submitting to always resetting it to false after the onSubmit handler had returned (or it's promise). This adds back to the version 1 behaviour of not touching the isSubmitting state after the onSubmit handler has been called if we don't return a promise in the onSubmit handler. Solves: jaredpalmer#1957
I've updated my PR to enable both old + new behavior. The documentation is not updated yet there. However I don't think that is a good solution. I can understand having The use case for the old method was also to have it as a this form is submitted and should not be submittable again. Either continue only with v2, allow it to be left in an Either way (even if we do the dual version) I'll continue to update the PR. |
In version 2 the behaviour of isSubmitting was changed from having the user handle its state after submitting to always resetting it to false after the onSubmit handler had returned (or it's promise). This adds back to the version 1 behaviour of not touching the isSubmitting state after the onSubmit handler has been called if we don't return a promise in the onSubmit handler. Solves: #1957
Fixed in 2.1 |
Causing issue in |
I can still repro this on The current docs are accurate:
So either this issue should be re-opened, or we should accept the new behavior. |
i solved like this:
I think it can be a workaround |
Thanks! This was the solution for me. |
IF YOU USING REDUX STORE OR ANY ASYNCFROM COMPONENT
FROM REDUX ACTION
|
馃悰 Bug report
Current Behavior
setSubmitting method not changing FormikProps isSubmitting
Your environment
The text was updated successfully, but these errors were encountered: