After validator against another field

Is there a way to use the after validator (or any of the date comparison validators) against another field without it failing if the target date is not a valid date? Right now it is set up to throw a coldfusion error if that target date is not a valid date. For example if I have a start date and an end date and I want to compare that the end date is after the start date and I set up the constraints in my model like this:

StartDate : {
	required: true,
	type: "date",
EndDate : {
	required: true,
	type: "date",
	after: "StartDate",

If I enter a valid end date, but enter an invalid start date the after validation will fail and throw a coldfusion error. Is there a way to force it to only do the after validation if the startDate is valid? Or should this behave the same way it does when the target date is empty and just return true?

I know I can just use a method validator to get the result I want, but was hoping to find a way to use the built in validation functions whenever possible.


@nhogan Are you saying that the invalid start date is basically that the field is NOT a date? Well, that would be caught by the type constraint since you are saying that this field better be a date or fail right?

@lmajano So that is what I hoped would happen, but it doesn’t. The reason it doesn’t is that the after constraint is on the EndDate field, but the type validator that fails is on the StartDate field. So while the StartDate field does fail the type validation, it doesn’t matter because when the EndDate field validation happens the after validator throws a CF error because StartDate isn’t a valid date. The type validator failing on the StartDate doesn’t short circuit the EndDate after validator which causes it to throw an error.

Ahhh I see. I think you are right. We shouldn’t be throwing an exception, we should just be invalidating the validation. I will update it.

Awesome, thanks Luis!