我在我的 asp.net core mvc 项目中使用 tarruda's bootstrap date picker,并且我在配置中将 startDate 设置为 09/01/2009,因此用户无法在该时间之前输入日期。>
如果用户输入日期,比如 08/31/2009(必须手动完成),一旦用户模糊了我们的字段,该字段就会被清除。
这很好,但有没有办法向用户显示验证消息,而不是仅仅清除字段?
我对日期选择器的初始化:
setupDatepickers() {
let dpConfig = this.getDatePickerConfig();
$('#Date').datepicker(dpConfig)
}
getDatePickerConfig() {
let d = new Date();
let utc = d.getTime() + (d.getTimezoneOffset() * 60000);
let nd: Date;
if (this.isDSTObserved(d)) {
nd = new Date(utc + (3600000 * -4));
}
else {
nd = new Date(utc + (3600000 * -5));
}
let dpConfig = {
startDate: new Date(2009, 9 - 1, 1),
format: 'mm/dd/yyyy',
endDate: nd,
autoclose: true
}
return dpConfig;
}
我的日期字段如下所示:
<div class="field col-6">
@Html.EditorFor(x => x.Date, new { htmlAttributes = new { placeholder = " ", @type = "text" } })
@Html.LabelFor(x => x.Date, new { @class = "date" })
@Html.ValidationMessageFor(x => x.Date, "", new { @class = "text-danger" })
</div>