This is a migrated thread and some comments may be shown as answers.

Telerik MVC Grid Skip Custom Validation on Tab Out

2 Answers 108 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jaired
Top achievements
Rank 1
Jaired asked on 26 Feb 2019, 02:58 PM

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);

2 Answers, 1 is accepted

Sort by
0
Jaired
Top achievements
Rank 1
answered on 26 Feb 2019, 07:39 PM

Upon further reading, I was looking for a way to disable validateOnBlur. There is not any explicit documentation for doing this in ASP.NET MVC, so I based my solution off of this.

After hooking up a grid edit event,

@(Html.Kendo().Grid<AppName.ViewModel>()
        ...
        .Events(events => events.Edit("onGridEdit"))
        ...
    )

I deleted the set event:

function onGridEdit(e) {
   //removes validate on blur.
   e.model._events.set;
}
0
Viktor Tachev
Telerik team
answered on 28 Feb 2019, 08:07 AM
Hi Jaired,

In order to detect duplicate values you can add Remote Validation to the Grid component. The following example shows how the feature works:




Regards,
Viktor Tachev
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Jaired
Top achievements
Rank 1
Answers by
Jaired
Top achievements
Rank 1
Viktor Tachev
Telerik team
Share this question
or