我有以下架构:
Dates.attachSchema(new SimpleSchema({
description: {
type: String,
label: "Description",
max: 50
},
start: {
type: Date,
autoform: {
afFieldInput: {
type: "bootstrap-datepicker"
}
}
},
end: {
type: Date,
autoform: {
afFieldInput: {
type: "bootstrap-datepicker"
}
}
}
}));
如何验证end日期不在之前start?我正在使用 MomentJS 来处理日期类型,但是我的主要问题是如何访问custom函数中的其他属性。
例如:
end: {
type: Date,
autoform: {
afFieldInput: {
type: "bootstrap-datepicker"
}
},
custom: function() {
if (moment(this.value).isBefore(start)) return "badDate";
}
}
我怎样才能访问start?
此外,我如何验证start+end日期组合是否是唯一的,这意味着我的数据库中没有保存start与end日期完全相同的文档?