我正在尝试使用自定义验证规则使用kendo验证程序,只有在选中复选框时才需要创建文本框。但是当我点击提交按钮时,这个customRule1正在以所需的形式创建所有字段。请帮助我缺少什么?
var pilotType = document.getElementById("PilotType");
var validator = $("#frmAddDetails").kendoValidator({
rules: {
customRule1: function (input) {
if (input.is("[id = chkPilotPresent]").checked) {
pilotType.setAttribute("required", "required");
}
}
},
errorTemplate: "<span></span>",
validate: function (e) {
var html = "";
e.preventDefault();
if (!e.valid) {
var errors = this.errors();
var requiredFieldCount = 0;
html += "<ul>";
for (var i = 0; i < errors.length; i++) {
if (errors[i].toLowerCase().indexOf("required") > 0 && requiredFieldCount == 0) {
html += "<li> Please enter mandatory Fields *</li>";
requiredFieldCount++;## Heading ## }
else if (errors[i].toLowerCase().indexOf("required") < 0) {
html += "<li>" + errors[i] + "</li>";
}
}
html += "</ul>";
}
$("#errors").html($(html));
}
}).data("kendoValidator");