Hello,
I am trying to implement custom rules for validator, where we need to make certain input fields mandatory only when a check box is selected. But not able to get it to work, can you please point out if i missed out anything in below -
var validator = $("#form1").kendoValidator({ 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++; } else if (errors[i].toLowerCase().indexOf("required") < 0) { html += "<li>" + errors[i] + "</li>"; } } html += "</ul>"; } $("#errors").html($(html)); } }).data("kendoValidator");
Custom Rule -
$(function () {
var container = $("#form1");
kendo.init(container);
container.kendoValidator({
rules: {
InsuranceAmount: function (input) {
if (input.context.id == "" && input.val() != "") {
return $("#.HasInsurance:checked");
}
return true;
}
}
});
});