-
Notifications
You must be signed in to change notification settings - Fork 123
Support async validation in field level #173
Comments
After the discussion with Mosoc in Mosoc#1. Here are the summary:
|
@abz53378 First, it should be valid when using async validator, with async/await syntax, and no return value in definition. Because the function with async syntax always return promise, even It don't have return value. const asyncExample = async () => {}
console.log(asyncExample())
> Promise {<resolved>: undefined} The resolved value actually fits Also, I want to check those condition statement:
And finally, for condition:
|
@Mosoc, you are right, the case you mentioned should be valid, and I already edited my comment. |
Okay. As workaround, make it throw error when validator is not a function in runtime . if(!isFunction(validator)) {
throw 'Validator should be a function'
} |
Is your feature request related to a problem? Please describe.
It's a wide-used feature for checking username availability, filtering forbidden words in the content, or any other computing/request which need to take a certain amount of run time.
Describe the solution you'd like
It seems that making validation.validator perform not only synchronous function call but also asynchronous one with
Promise
is Intuitive way.How to implement
The quick way in babel era is use async/await syntax.
But I think there are still some compatibility or performance issues.
For
Promise
only case, I prefer the method in Formik source code and doc, whichPromisify
either async function or normal one.As this way, we can
Promisify
all the validate handle include orginal ajv validation.Then, we can use Promise.all and map reduce to handle results and errors clearly.
The text was updated successfully, but these errors were encountered: