resolvers: Yup resolver problem with test function
Hello,
It seems there is a problem with the yupResolver
, when there is a schema with test
function.
This a CodeSandbox to reproduce the problem: https://codesandbox.io/s/yup-resolver-problem-with-yup-test-function-16r4d?file=/src/App.js
The form example has 3 inputs. The age is required, only here to illustrate that individual field can throw, as expected, an error.
But the test
function, which checks if email or name are present, does not throw a ValidationError.
The onSubmit
method shows that there is no error and that the data is an empty object. 😢
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 31 (18 by maintainers)
Commits related to this issue
- fix #43 with yup.test — committed to react-hook-form/resolvers by bluebill1049 4 years ago
Yup’s validation doesn’t work as expected even for
required
for file types when using with resolver. Wasted so much time on this to work but nothing worked. Finally removed the file validation from Yup and handled on server side. Still Looking for the solution.So the quick fix for now is to return true (or false 🤷) if the validation passes, and to
throw Error
if the validation fails. This will create an error with name ‘undefined’… not ideal, but is a good enough patch until I figure out whats going on.hey @pmaier983, would you be interested to give a crack on this one?
It’s not that. The undefined is due to the custom resolver and how it rebuilds an error object.
But Yup has sended this:
I suspect that “path”:“this”, is not well evaluated and returns undefined.