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

Grid Custom Validation - Multiple fields Access

3 Answers 831 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 28 Mar 2018, 11:16 AM

I have a business requirement that I don't know how to quite handle using the grid.  I have set up inline batch editing on a grid for a customer.  One of the requirements is to do client side business logic to validate the data before allowing the Save Changes functionality to work. 

My grid is set up something like this

ColA    ColB    ColC    ColD

10           0         0           0

The requirement is that if any of those 4 columns has a value, all the columns must have a non-zero value. I'm not sure how to access the ids/values of  ColB, ColC, ColD so that I can do the comparison in the javascript.  When I took a look using firebug, each of those fields had a guid identifier (screenshot below).

The code I am playing around with is as follows 

//register custom validation rules
   (function ($, kendo) {
       $.extend(true, kendo.ui.validator, {
           rules: { // custom rules
               productnamevalidation: function (input, params) {
                   if (input.is("[name='operating_hrs']") && input.val() != "") {
                       input.attr("data-productnamevalidation-msg", "Product Name should start with capital letter");
                       if (input.val() != 24)
                       {
                           var input1 = $('input[data-bind="value:hrsepwr_hrs"]');
                           var input2 = input1.val();
                           alert(input2);
                           //alert($('#station_id').val());
                           return false;
                        }
                       //return /^[A-Z]/.test(input.val());
                   }
 
                   return true;
               }
           },
           messages: { //custom rules messages
               productnamevalidation: function (input) {
                   // return the message text
                   return input.attr("data-val-productnamevalidation");
               }
           }
       });
   })(jQuery, kendo);

3 Answers, 1 is accepted

Sort by
0
Michael
Top achievements
Rank 1
answered on 29 Mar 2018, 12:43 PM
I think I have it now... 
0
Stefan
Telerik team
answered on 02 Apr 2018, 05:43 AM
Hello, Michael,

I`m glad to hear that you have found an approach.

Our recommendation is to find the row dataItem based on the current input:

var row = input.closest("tr");
var grid = $('#gridID').data().kendoGrid;
var dataItem = grid.dataItem(row);

https://docs.telerik.com/kendo-ui/api/javascript/ui/grid/methods/dataitem

I hope this is helpful.

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Michael
Top achievements
Rank 1
answered on 02 Apr 2018, 02:58 PM

I found this on another post, and it seems to work great

 

var grid = $('#grid').data('kendoGrid');
var selectedRow = grid.dataItem('tr.k-grid-edit-row');

var opHours = selectedRow.operating_hrs

Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Michael
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or