Greetings,
I have a Telerik MVC Grid with in-line editing. It has custom validation to check if the primary key already exists, but it runs the validation when you tab out AND click "Update" in-line. How do I change the validation to occur and subsequently the error message to pop up ONLY on clicking "Update" and not when leaving the textbox? Here is my code below:
01.
(
function
($, kendo) {
02.
$.extend(
true
, kendo.ui.validator, {
03.
rules: {
// custom rules
04.
codevalidation:
function
(input, params) {
05.
if
(input.is(
"[name='Code']"
) && input.val() !=
""
) {
06.
input.attr(
"data-codevalidation-msg"
,
"Code must not already exist."
);
07.
08.
var
isGood =
true
;
09.
var
gridData = $(
"#grid"
).data(
"kendoGrid"
).dataSource.data()
10.
11.
console.log(input.val());
12.
for
(
var
i = 1; i < gridData.length; i++) {
13.
console.log(gridData[i].Code == input.val().toUpperCase())
14.
if
(gridData[i].Code == input.val().toUpperCase())
15.
isGood =
false
;
16.
}
17.
console.log(
"returning "
+ isGood);
18.
return
isGood;
19.
}
20.
else
{
21.
22.
return
true
;
23.
console.log(
"returning true at end"
);
24.
}
25.
}
26.
},
27.
messages: {
//custom rules messages
28.
codevalidation:
function
(input) {
29.
// return the message text
30.
return
input.attr(
"data-val-codevalidation"
);
31.
}
32.
}
33.
});
34.
})(jQuery, kendo);