Hi there,
Could you let me know how can one traverse the schema in the test method and reach a grandparent (this.parent.parent). this.parent works fine but this.parent.parent === undefined.
Thanks,
there isn't a way to do this at the moment. only the current parent is stored
Is there a way to validate array of objects in an object?
{min: 10, values: [{moreThanMin: 11}]}
I know that this is being worked on the #201 (a WIP), but do we have a workaround for it? I need to display a field depending the value of another field and I couldn't find a way to access the info because I cannot access a sibling node from its parent node :(
The only workaround would be to stick your top level value in context when you validate and reference that in the test
thanks @jquense
// my data structure
{
ipVersion: 4,
tunnel: {
gateway: {
ip: 'xxxx', <--- IPv4 or 6 depend on top level `ipVersion`
mac: 'xxx'
}
}
}
.when('ipVersion', {
is: (value, originalValue) => { <-- why not pass the full 'values' so we can get the value I want?
return originalValue.ipVersion === 4;
},
// getValue: originalValue => originalValue.ipVersion <-- or custom getter ?
then: ipv4(),
otherwise: ipv6()
})
since I am seeing the originalValue this there in the conditional.js already:

And, this use case seems to be a very universal requirement IMO,
(I have seeing several similar issue like https://github.com/jaredpalmer/formik/pull/522, https://github.com/jaredpalmer/formik/issues/506, https://github.com/jaredpalmer/formik/issues/503), why can't we have this in Yup so we don't have to make some hacky workaround?
@yanzou The only thing keeping anyone from having it is someone writing it. If you want to see it in yup send a PR
@jquense how about those 2 PRs?
https://github.com/jquense/yup/pull/201
https://github.com/jquense/yup/pull/556
I am seeing people trying to fix the issue but no more grogress
Most helpful comment
The only workaround would be to stick your top level value in
contextwhen you validate and reference that in the test