看到这个链接
我的仅验证是否输入了日期,如果日期选择器字段为空,则会从 kendo 隐藏所有验证标签。
它满足您上面描述的场景,除了我发布成功的表格。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Kendo UI Snippet</title>
<link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1119/styles/kendo.common.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1119/styles/kendo.rtl.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1119/styles/kendo.default.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1119/styles/kendo.dataviz.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1119/styles/kendo.dataviz.default.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1119/styles/kendo.mobile.all.min.css">
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://cdn.kendostatic.com/2014.3.1119/js/kendo.all.min.js"></script>
</head>
<body>
<form id="myform">
<input name="myDate" class="validateDate" id="startDate" /> <br />
<input name="myDate" class="validateDate" id="endDate" />
<button>Validate</button>
</form>
<script>
$("#myform").kendoValidator({
rules: {
dateValidation: function(input) {
//only validate
if (input.hasClass('validateDate')) {
if(input.val() !== ""){
return kendo.parseDate(input.val(), "dd/MM/yyyy");
}
else{
input.siblings("span.k-tooltip-validation").hide();
return true;
}
}
}
},
messages: {
dateValidation: "Please enter a date in the format dd/mm/yyyy"
}
});
$("#startDate, #endDate").kendoDatePicker({ format: "dd/MM/yyyy", culture: "en-GB" })
</script>
</body>
</html>