Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supporting this.parent.parent call #165

Closed
sundriver opened this issue Jan 15, 2018 · 9 comments
Closed

Supporting this.parent.parent call #165

sundriver opened this issue Jan 15, 2018 · 9 comments

Comments

@sundriver
Copy link

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,

@jquense
Copy link
Owner

jquense commented Jan 15, 2018

there isn't a way to do this at the moment. only the current parent is stored

@psixdev
Copy link

psixdev commented Feb 9, 2018

Is there a way to validate array of objects in an object?
{min: 10, values: [{moreThanMin: 11}]}

@sergioviniciuss
Copy link

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 :(

@jquense
Copy link
Owner

jquense commented Jul 26, 2018

The only workaround would be to stick your top level value in context when you validate and reference that in the test

@sergioviniciuss
Copy link

thanks @jquense

@yanzou
Copy link

yanzou commented May 14, 2020

// 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:

image

And, this use case seems to be a very universal requirement IMO,
(I have seeing several similar issue like jaredpalmer/formik#522, jaredpalmer/formik#506, jaredpalmer/formik#503), why can't we have this in Yup so we don't have to make some hacky workaround?

@jquense
Copy link
Owner

jquense commented May 15, 2020

@yanzou The only thing keeping anyone from having it is someone writing it. If you want to see it in yup send a PR

@yanzou
Copy link

yanzou commented May 15, 2020

@jquense how about those 2 PRs?
#201
#556
I am seeing people trying to fix the issue but no more grogress

@FrankyCTY
Copy link

The only workaround would be to stick your top level value in context when you validate and reference that in the test

Too good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants