How to create validation rule using multiple properties

I’m trying to validate an object that has beginDate and endDate properties. As part of the validation, I need to ensure that beginDate is “before” endDate. I tried doing the following:

 .ensure((s:Session) => s.beginDate)
   .satisfies((s:Session) => moment(s.beginDate).isBefore(s.endDate))

Of course, this doesn’t work because the beginDate – not the Session object – is what is actually being passed to the satisfies() function.

How can I get access to both beginDate and endDate in the satisfies() validation rule?

1 Like

I was finally able to resolve this with the following:

  .customRule('datecompare',(value,obj : Session,endRangeProperty : string) => {
     return value === null
        || value === undefined
        || obj[endRangeProperty] === null
        || obj[endRangeProperty] === undefined
        || moment(value).isBefore(obj[endRangeProperty]);
   }, "${$displayName} must come before ${$getDisplayName($config.endRangeProperty)}."
    , (endRangeProperty) => ({endRangeProperty}));

   .ensure((s:Session) => s.StartDate)