resolvers
resolvers copied to clipboard
Yup errors are swallowed
Describe the bug
When a field has multiple errors, just the one higher in the hierarchy is reported, despite setting criteriaMode: 'all' and earlyAbort: false.
To Reproduce Steps to reproduce the behavior:
- Open the sandbox
- Click on Submit
- Open the console
- Notice there is a single error for the items field: "items field must have at least 2 items"
- Now, uncomment line 45
- Reload the page
- See it now reports errors on items that should have been reported along with the minimum number of items requirement
Codesandbox link (Required) https://codesandbox.io/s/modest-butterfly-7noyn0?file=/src/App.tsx
Expected behavior All errors.
hook form reconcile errors based on the field name, if you want a group level, you can consider to use trigger('group')
I've tried that. It doesn't work either: https://codesandbox.io/s/modest-butterfly-7noyn0?file=/src/App.tsx
then follow the doc try to debug why it's not trigger the error
resolver: async (data, context, options) => {
// you can debug your validation schema here
console.log('formData', data)
console.log('validation result', await anyResolver(schema)(data, context, options))
return anyResolver(schema)(data, context, options)
},
I can confirm it's an issue related to the Yup resolver:

Yup correctly reports the errors: https://codesandbox.io/s/yup-forked-0xsspo?file=/src/index.js

I've updated the code sandbox to make the issue more explicit:

It doesn't look like the errors object has associated with the field name, going back to the original comment hook form will require errors to be associated with fields.
https://github.com/react-hook-form/resolvers/blob/master/yup/src/yup.ts#L14-L39
Even associating a field name it doesn't work:

I meant the schema, does the schema errors return the field associate path to that field array? Please refer to the source code which i posted above.
Yes:

Is it because Yup uses square bracket notation? I don't think so, since the errors are correctly reported when no errors above exist.
Ok, I found the problem. The set method is overriding the item[0] error since it's reported before the item.
This is the value of fieldErrors at each iteration:

Could you please reopen the issue?
