Yup Custom Validation (addMethod) Bug
See original GitHub issueDescribe the bug Code breaks when adding custom validation logic via addMethod function.
Code returns : vendors-node_modules_apollo_client_index_js-node_modules_hookform_resolvers_yup_dist_yup_modu-7f163c.js:9521 Uncaught (in promise) TypeError: Cannot read property ‘reduce’ of undefined message.
To Reproduce Just add custom validation to yup
yup.addMethod(yup.object, 'localeEqual', function (errorMessage) {
return this.test('locale-equal', errorMessage, function (value) {
const {path, createError} = this
return value.kz.length === value.ru.length || createError({path, message: errorMessage})
})
})
CodeSandbox https://codesandbox.io/s/yup-custom-validation-error-41x1n?file=/src/App.js
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
How Does yup.addMethod() Work? Creating Custom ...
Yup's documentation is pretty vague about creating custom validation functions and the role of .addMethod() in it. This article will break it down...
Read more >Does anyone have an example of `addMethod` in Typescript?
Context: I'm using Yup with Typescript and formik. Trying to add a custom method to enforce the format of a date value. The...
Read more >How to write a custom schema validation using yup ...
My validation seems to work, but I find it too verbose. Trying to use the .addMethod() function of yup , but getting stuck...
Read more >How to use the yup.addMethod function in yup - Snyk
To help you get started, we've selected a few yup.addMethod examples, based on popular ways it is used in public projects.
Read more >Yup - npm
Dead simple Object schema validation. Latest version: 0.32.11, last published: a year ago. Start using yup in your project by running `npm i ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You got that error because
value
could beundefined
, here is the fixed part:This line:
value.en?.length === value.ru?.length
Let me know if you still have the issue
Thanks so much, @sanzhardanybayev that’s awesome to hear!