Skip to content
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

submit() returns undefined instead of a Promise if there are async field validations #420

Open
cdauth opened this issue Jun 13, 2021 · 1 comment

Comments

@cdauth
Copy link

cdauth commented Jun 13, 2021

I'm new to final-form, sorry if I'm missing or misunderstood something. I am trying to implement a form using react-final-form whose submit button shows a loading spinner and is disabled while the form is submitting. My form has some async field validators.

To detect when the form is submitting, I cannot use formState.submitting, because it is only set to true after all the validations have finished. It means that there is no immediate visual feedback when the user clicks the submit button. I also cannot use formState.validating || formState.submitting, because the form also validates when a value in the form is changed, so the submit button will be spinning/disabled even though the user didn't press it yet.

What I am trying to do instead is manage the submitting state by hand and set it to true when the submit button is clicked and false when the promise returned by formApi.submit() is resolved. Unfortunately, formApi.submit() returns undefined if the async validations have not been run yet or are still in progress. Only if all async validations have already finished when the submit button is pressed, the function returns a promise. This behaviour can also be clearly seen in the source code.

I believe that formApi.submit() should always return a Promise that is resolved when all validations and submission has been done. It also seems to me that it would be better if formState.submitting were already true while the validations are running due to calling formApi.submit().

I'm also interested whether anyone has a suggestion for a workaround.

@Deckstar
Copy link

Not the official package, but I fixed this in final-form-ts 1.0.12 😇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants