Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AJV resolver is async mode is not working #665

Open
denyskublytskyi opened this issue Mar 3, 2024 · 0 comments
Open

AJV resolver is async mode is not working #665

denyskublytskyi opened this issue Mar 3, 2024 · 0 comments

Comments

@denyskublytskyi
Copy link

Describe the bug
The Async mode for AJV is not working. It's not handling promise here https://github.com/react-hook-form/resolvers/blob/master/ajv/src/ajv.ts#L71

https://ajv.js.org/guide/async-validation.html

To Reproduce
Steps to reproduce the behavior:

Codesandbox link (Required)
Include a codesandbox will help us to investigate the issue quicker.

https://codesandbox.io/p/sandbox/react-hook-form-validationschema-v6-2l77g

Expected behavior
Error message for field instead of the uncaught error.

Screenshots

Screenshot 2024-03-03 at 18 53 43

Desktop (please complete the following information):

  • OS: [MacOS]
  • Browser [Chrome]
  • Version [122]

Additional context
https://github.com/react-hook-form/resolvers/blob/master/ajv/src/ajv.ts#L71

Fix:

let valid = false;
if (resolverOptions?.mode === 'sync') {
  valid = validate(values);
} else {
  try {
    valid = await validate(values);
  } catch (e) {
    if (e instanceof Ajv.ValidationError) {
      validate.errors = e.errors as DefinedError[];
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant