-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Multiple alternatives with default #763
Comments
This is currently a bug I meant to tackle a while ago. |
Sorry for the delay, fix is finally published. const schema = Joi.object({
a: Joi.string().required(),
b: Joi.when('a', { is: 'Other', otherwise: Joi.string().required() }),
c: Joi.string()
.when('a', { is: 'Other', then: Joi.required() })
.when('b', { is: 'Other', then: Joi.required() })
}); As you can see from b and c, type of the alternative can be inside or outside whether you want it to be a string anyway, your choice. |
My project is almost same as yours. But in my project a is array. When I wrote a: Joi.array().required(), |
Stop spamming dude and open your own issue. |
Imagine than we have a,b,c fields.
a
- is always required.b
- required only ifa
!= 'Other'c
- required only ifa
== 'Other' ORb
== 'Other'If none of
c
rules has been appliedc
should be optional()How should I rebuild my schema to get last rule working?
The text was updated successfully, but these errors were encountered: