-
Notifications
You must be signed in to change notification settings - Fork 934
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
is it possible to have nested .whens()? #335
Comments
.whens()
?
Nested
|
Hi, @jquense. Is it possible at all? And how it could be achieved? I mean, nesting passport: yup.string().whenLawful(
schema => schema.passport().whenServicesSelected(
passportSchema => passportSchema.required('Passport is required'),
passportSchema => passportSchema.notRequired(),
),
schema => schema.notRequired(),
), |
@ugeng at the moment no there isn't any support for it. There isn't a strong reason why, but it's complicated enough that it's not super simple to add. I'm happy to evaluate a PR tho if someone is up for it. |
Well, I suppose, strong reasons are purity, readability and testability of code... |
While this doesn’t exist yet, have anyone found a workaround or would have a suggestion on how do deal with a validation like the following? const schematic = Yup.object().shape({
aBoolean: Yup.boolean(),
aThing: Yup.object().when("aBoolean", {
is: true,
then: Yup.object().shape({
aString: Yup.string(),
anotherString: Yup.string().when("aString", {
is: "theRightThing",
then: Yup.string().required()
})
}).required()
})
}) |
@jquense any plans to support nested whens? |
As of quarantine 2020, this now works as you think it should:
|
I think the .nullable() is still not handled in nested "whens" |
I'm trying to achieve nested .when() calls, but with no success.
I'm trying something similiar to the following example:
Does anyone have an idea of how can I achieve that?
The text was updated successfully, but these errors were encountered: