Version Number
7.27.0
stackblitz demo
https://stackblitz.com/edit/react-poscya
Steps to reproduce
- Go to stackblitz demo
- Open console under the app window
- Type
taken
into Lastname input field (there is a 1s delay on purpose) - Type anything or blur Firstname input field
- See output in console
ASYNC validation STARTED
andASYNC validation DONE
after 1s
Firstname field has not async validation:
test('firstName', 'Field is required', () => { enforce(formValue.firstName).isNotEmpty(); });
Lastname field has async validation:
test('lastName', 'ASYNC field is required', async () => { await new Promise((resolve, reject) => { setTimeout(() => { if (formValue.lastName === 'taken') { reject(); } else { resolve(true); } }, 1000); }); });
This is a problem if you need to check the username availabilty on the server.
Expected behaviour
Async validation should not run on blur/change another fields.
More information
-
mode: 'all'
is used with useForm -
There is vest resolver used (vest@4.1.3)
-
I agree to follow this project’s Code of Conduct
Yes, it was schema validation behaviour – Vest resolver.
Here is working demo (in case that someone has similar issue).
Line
only(currentField);
has fixed the issue.