问题描述
我希望验证页面上的日期字段,这很简单(请参见此JSBin ).但是,当页面在页面上有多个日期字段时,事情开始变得古怪...
I'm looking to validate date fields on a page, which is simple (see this JSBin). BUT, when a page has multiple date fields on a page things start to get wacky...
请参见此JSBin ,并使用无效的日期进行播放.
See this JSBin and play around with invalid dates.
无效消息不知道要绑定到哪个输入,从而在错误的输入上导致错误消息.有没有办法触发正确的输入字段?
The invalid message doesn't know which input to bind to, causing error messages on the wrong inputs. Is there a way to trigger the correct input field?
推荐答案
不是为表单定义验证器,而是为每个实际要验证字段而不是整个表单的日期定义验证器.您可以按照以下方式进行操作:
Instead of defining a validator for the form, define a validator for each date as actually you want to validate the fields and not the form as a whole. You can do it as:
$(".datepicker").kendoDatePicker();
$(".datepicker").kendoValidator({
rules : {
//implement your custom date validation
dateValidation: function (e) {
console.log("e", e);
var currentDate = Date.parse($(e).val());
//Check if Date parse is successful
if (!currentDate) {
return false;
}
return true;
}
},
messages: {
//Define your custom validation massages
required : "Date is required message",
dateValidation: "Invalid date message"
}
});
您的JSBin修改了此处
Your JSBin modified here
这篇关于页面上有多个日期字段时的KendoUI DatePicker验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!