简单模式 minDate maxDate
Simple Schema minDate maxDate
我认为这是一个简单的问题。我使用的是简单模式,我想要一个 minDate 和 maxDate。文档在验证部分讨论了它,但我不确定如何在模式本身中定义它。任何帮助都会很棒。谢谢
路径:Schema.js
startDate: {
type: Date,
optional: true,
autoform: {
type: "bootstrap-datepicker"
}
},
endDate: {
type: Date,
optional: true,
autoform: {
type: "bootstrap-datepicker"
}
}
我在 simple-schema repo 中发现了一个与此相关的问题。以下是使用静态 min/max 日期时代码的外观:
startDate: {
type: Date,
optional: true,
min: new Date(2016, 1, 1),
autoform: {
type: "bootstrap-datepicker"
}
},
endDate: {
type: Date,
optional: true,
max: new Date(2018, 1, 1),
autoform: {
type: "bootstrap-datepicker"
}
}
如果您想使这些日期动态化,您可以使用 custom
验证器。这是相关文档的a link。您的开始日期将如下所示:
startDate: {
type: Date,
optional: true,
custom: function() {
var myMinDate = new Date(); //today
if(myMinDate > this.value) {
return 'minDate'; //Error string according to the docs.
} else {
return true;
}
},
autoform: {
type: "bootstrap-datepicker"
}
},
endDate: {
type: Date,
optional: true,
custom: function() {
var myMaxDate = new Date(2018, 11, 31); //Last day of 2018
if(myMaxDate < this.value) {
return 'maxDate'; //Error string according to the docs.
} else {
return true;
}
},
autoform: {
type: "bootstrap-datepicker"
}
}
我认为这是一个简单的问题。我使用的是简单模式,我想要一个 minDate 和 maxDate。文档在验证部分讨论了它,但我不确定如何在模式本身中定义它。任何帮助都会很棒。谢谢
路径:Schema.js
startDate: {
type: Date,
optional: true,
autoform: {
type: "bootstrap-datepicker"
}
},
endDate: {
type: Date,
optional: true,
autoform: {
type: "bootstrap-datepicker"
}
}
我在 simple-schema repo 中发现了一个与此相关的问题。以下是使用静态 min/max 日期时代码的外观:
startDate: {
type: Date,
optional: true,
min: new Date(2016, 1, 1),
autoform: {
type: "bootstrap-datepicker"
}
},
endDate: {
type: Date,
optional: true,
max: new Date(2018, 1, 1),
autoform: {
type: "bootstrap-datepicker"
}
}
如果您想使这些日期动态化,您可以使用 custom
验证器。这是相关文档的a link。您的开始日期将如下所示:
startDate: {
type: Date,
optional: true,
custom: function() {
var myMinDate = new Date(); //today
if(myMinDate > this.value) {
return 'minDate'; //Error string according to the docs.
} else {
return true;
}
},
autoform: {
type: "bootstrap-datepicker"
}
},
endDate: {
type: Date,
optional: true,
custom: function() {
var myMaxDate = new Date(2018, 11, 31); //Last day of 2018
if(myMaxDate < this.value) {
return 'maxDate'; //Error string according to the docs.
} else {
return true;
}
},
autoform: {
type: "bootstrap-datepicker"
}
}