-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
supportQuestions, discussions, and general supportQuestions, discussions, and general support
Description
Is it possible to validate between two dates that are optional?
var schema = Joi.object().keys({
fromDate: Joi.date().max(Joi.ref('toDate')).allow(''),
toDate: Joi.date().min(Joi.ref('fromDate')).allow('')
});
Joi.validate({ fromDate: new Date(), toDate: '' }, schema, function (err, value) {
if (err) console.error(err);
console.dir(value);
});
prints out to the console:
{ [ValidationError: child "fromDate" fails because ["fromDate" references "toDate" which is not a date]]
name: 'ValidationError',
details:
[ { message: '"fromDate" references "toDate" which is not a date',
path: 'fromDate',
type: 'date.ref',
context: [Object] } ],
_object:
{ fromDate: Sat Oct 24 2015 20:31:20 GMT-0400 (Eastern Daylight Time),
toDate: '' },
annotate: [Function] }
daronwolff and Rovack
Metadata
Metadata
Assignees
Labels
supportQuestions, discussions, and general supportQuestions, discussions, and general support