issue: async validation triggers on any field blur/change with mode ‘all’

Version Number

7.27.0

stackblitz demo

https://stackblitz.com/edit/react-poscya

Steps to reproduce

  1. Go to stackblitz demo
  2. Open console under the app window
  3. Type taken into Lastname input field (there is a 1s delay on purpose)
  4. Type anything or blur Firstname input field
  5. See output in console ASYNC validation STARTED and ASYNC 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

1 thought on “issue: async validation triggers on any field blur/change with mode ‘all’

  1. 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.

Comments are closed.