Closed eseceve closed 3 years ago
Hi @eseceve,
In your example you applied 2 validators one is Sync and one is Async.
Async validators run only if all the Sync validations have passed, no otherwise.
Reasons why is this way is to avoid calling async functions if your form is not valid.
Hope it helped.
<TextField
label="Standard"
name="standard"
touched
validators={[required]}
/>
<TextAsyncField
label="Filled"
variant="filled"
name="filled"
validator={asyncRequired}
/>
Async validators run only if all the Sync validations have passed, no otherwise.
Reasons why is this way is to avoid calling async functions if your form is not valid.
The problem that I see with this approach it's I can't use only async validations in my forms. I'll need to write an asyncValidation for the form too, not just for each input.
I would like to run async validations of each input on submit if there aren't validated yet
Would you please describe me a case in which you need to run an async validator function if a sync fails? Thanks
I don't know why I had assumed that I couldn't use validators
andasyncValidator
at the same time.
I already understood how to do what I need.
Hi @eseceve,
You can apply both validations sync and async on the same input or different inputs.
Priority is given to sync, so if one sync functions fails the async validators will not be excuted.
If you like usetheform a github star will be appriciated.
Thanks.
Problem
Submit event doesn't trigger async validations of each input
Current Behavior
Just only runs sync validations of each input
Expected Behavior
Run sync and async validations of each input
Demo
https://codesandbox.io/s/usetheform-asyncvalidators-submit-blbto