I have currently added the following custom validation to my interest name, but interest name has to be unique, so when user add new and existing interest name is already there, it will throw error. However, when user try to edit the record, it should be able to detect whether current interest name is changed, if it is a new interset name then only check only uniqueness validation, otherwise, it should allow the update to go through successfully.
With the following validation, when i try to perform update, it also throw the validation error, and i am do not know how to make this validation valid for Add New all the time, and valid for Update only when interest name is changed.
(function ($, kendo) {
$.extend(true, kendo.ui.validator, {
rules: { // custom rules
InterestNamevalidation: function (input, params) {
if (input.is("[name='InterestName']") && input.val() != "") {
var dataSource = $("#Customer").data("kendoGrid").dataSource;
var data = dataSource.data();
for (var i = 1; i < data.length; i++) {
if ($.trim(input.val().toLowerCase()) == $.trim(data[i].InterestName.toLowerCase())) {
input.attr("data-InterestNamevalidation-msg", "InterestName should be unique");
return false;
}
}
}
return true;
}
}
});
})(jQuery, kendo);