[QUESTION] Yup validation of multi level object
See original GitHub issueI am using Yup with formik. My values look like this:
"values": {
"startTime": "2019-10-13T01:04:11.596Z",
"endTime": null,
"phraseType": {
"id": "HELLO"
}
phraseValue: Yup.number().positive().when('phraseType', {
is: (val) => val.id === 'HELLO',
then: Yup.string().required('required'),
otherwise: Yup.string().notRequired()
}),
It doesn’t seem I am able to access the id off of the val object. Val is being returned as a string “[Object][Object]” instead of the actual object. How do I use when() with a key to get back an object?
Thanks!
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Yup nested schema validation - Stack Overflow
I'm trying to validate an object conditionally on a Select Option that's been chosen by a user, the issue is I'm rendering a...
Read more >Yup Email Validation: String Schema Code Examples
The Yup object schema provides two methods for validating: isValid ... Yup also gives us the ability to validate multiple emails at once, ......
Read more >How to internationalize a Yup validation schema in ... - Medium
In the CodeSandbox below, we have a basic setup of React, react-i18next, Formik and Yup. We display a form with a required email...
Read more >React Multi-Step Form Tutorial: Using Formik, Yup ... - YouTube
In this tutorial, we'll build a multi -step form using React, Formik and Yup for validation.In order to validate our forms, we will...
Read more >Formik with Advanced Yup Validation - React Forms - YouTube
In this tutorial we will check out the powerful validation we can do by integrating Yup with Formik!NEW TO FORMIK? Check out my...
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 FreeTop 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
Top GitHub Comments
ok thanks, I got everything up to the latest version. I found my problem. In my code I also had: phraseType: yup.string().required(), that needed to be phraseType: yup.object().required().
I updated my example if your interested. if you use the line: phraseType: yup.string().required(),
the validation fails
if you change it to: phraseType: yup.object().required(),
validation works. Not a bug, just letting you know. really appreciate you researching.
if you’re still stuck the reason your example is throwing is because
phaseType
is not defined in your schema.