Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
188
rated 0 times [  190] [ 2]  / answers: 1 / hits: 43573  / 10 Years ago, wed, october 22, 2014, 12:00:00

I have the following schema:



var testSchema = Joi.object().keys({
a: Joi.string(),
b: Joi.string(),
c: Joi.string().when('a', {'is': 'avalue', then: Joi.string().required()})
});


but I would like to add a condition on c field definition so that it is required when:



a == 'avalue' AND b=='bvalue'



How can I do that?


More From » hapi.js

 Answers
23

You can concatenate two when rules:



var schema = {
a: Joi.string(),
b: Joi.string(),
c: Joi.string().when('a', { is: 'avalue', then: Joi.string().required() }).concat(Joi.string().when('b', { is: 'bvalue', then: Joi.string().required() }))
};

[#69047] Monday, October 20, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
savanar

Total Points: 237
Total Questions: 105
Total Answers: 99

Location: Wales
Member since Mon, May 17, 2021
3 Years ago
;