0

I Want to put validation of end date should be max or equal from effective date if end date is there

effectiveDate: validator('presence', {
presence: true,
message: 'Please enter a valid value'
}), 

endDate: validator('presence', {
value(model, attribute) {
// Validate a value that is not the current attribute
var effectiveDate  = new Date(this.get('model').get('effectiveDate'));
var endDate  = new Date(this.get('model').get('endDate'));
 presence: effectiveDate > endDate;
},
message: 'Please enter a date value'
})

End date is not mendatory

2 Answers2

1

If you are using moment.js for date formatting etc. you can compare two dates with ".diff" like

var now = moment();
// new date if "your date" is formatted
moment(new Date(this.get('your_date'))).diff(now,'days')
// result is difference in days from given date to now

Search for "Invalid Moments" in the docs

0

Simple done with

endDate: validator('date', {

dependentKeys: ['effectiveDate'],
after : function () {
    return this.get('model').get('effectiveDate');
}
}),