我希望结束日期的验证应该是生效日期的最大值或相等,如果有结束日期
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'
})
结束日期不是修正
答案 0 :(得分:1)
如果您使用moment.js进行日期格式化等,可以将两个日期与“.diff”进行比较,如
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
答案 1 :(得分:0)
使用
完成endDate: validator('date', {
dependentKeys: ['effectiveDate'],
after : function () {
return this.get('model').get('effectiveDate');
}
}),