Search code examples
redux-formreact-redux-form

AsyncValidation and Uncaught promise in redux-form


I have implemented an asyncValidation in my redux-form and it works as expected. When I left the field, the data in the field will be validated by asyncValidation.

However if I click submit immediately leaving the field, I will get an error 'Uncaught (In promise)'

I know my submit handler is not implemented quite correctly. It does not return a promise. That's why the submitting property is always false. My submit hander simply dispatch an action to the redux store.

My question: what is the right way to write such a handler? Is there anything the submit handler has to know about the asyncValidation?

Version of "redux-form" is "^6.6.1"


Solution

  • I don't think the submit handler needs to return a promise when you use async validation, it's just that the asyncValidate function needs to return a promise in order for async validation to work.

    Apparantly the error you describe is a known regression; it used to be fixed in an earlier version, but it's back again now. See this GitHub issue for details: https://github.com/erikras/redux-form/issues/1297

    You can verify the exact situation you describe even in the example on the documentation site: http://redux-form.com/6.6.1/examples/asyncValidation/