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

asyncValidating does not reflect multiple incomplete promises #3950

Open
Olliebaba opened this issue Apr 1, 2018 · 1 comment
Open

asyncValidating does not reflect multiple incomplete promises #3950

Olliebaba opened this issue Apr 1, 2018 · 1 comment

Comments

@Olliebaba
Copy link

Olliebaba commented Apr 1, 2018

Are you submitting a bug report or a feature request?

Bug

What is the current behavior?

asyncValidating is set to false once the initial validation promise is complete even if subsequent async validations have been called before the first one completed.

NOTE: the asyncValidate is set to a 5 second delay.

  1. sandbox
  2. enter 'joh' and wait for 3 seconds.
  3. type 'n' and wait for two seconds
  4. click submit once it's enabled

The form will submit with 'john' successfully and will only display the error after 5 seconds( after step #3's promise completes).
If you look at the console, you can see that asyncValidating is set to false once the first promise is complete (for 'j').

What is the expected behavior?

The asyncValidating prop should be truthy as long as there is an incomplete async validation promise. It should revert to false only after all promises are complete.

Sandbox Link

sandbox

What's your environment?

redux-form 7.3.0

Other information

@Olliebaba
Copy link
Author

Olliebaba commented Oct 15, 2018

@erikras - I have a couple ideas on how this issue could be resolved and would like to make a pull-request. But first I would like to know how you would prefer this be approached.

Since the form prop asyncValidating is either a bool or a string, it does not reflect multiple, asynchronous validation processes. And once the first promise resolves, asyncValidating is set to false, allowing submission while there are still incomplete async validations. Because of the described behavior I have not been able to use async change validation in production. I have considered creating support for this issue outside of redux-form but thought I would explore addressing it within the library itself first.

My initial thought was to make asyncValidating an array or bool. So that whenever START_ASYNC_VALIDATION is called, it could add to or remove from the array, allowing for multiple async validations to be tracked. (using bool still for the final call onSubmit)

This approach however does create a breaking change as it would change asyncValidating's type. And does not address the fact that requests associated with the same field would not necessarily resolve in the same order.

I would like any input on this proposal. And if there's already anything in the works surrounding this, I'd like to contribute wherever's needed.

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

1 participant