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

Keydown Handler with Invalid Cell

1 Answer 37 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Koren
Top achievements
Rank 1
Koren asked on 27 Oct 2015, 10:23 PM

I am using a custom keydown function that works great to get enter to work as a tab in Add mode and to close and move down a row in Update mode (batch editing on the grid).  However, I just realized that the enter key is closing the cell and moving down even if the cell validation fails.  How do I check whether the cell is valid before moving off the cell?

Here is the portion of the keydown function that handles the enter key...

 

if (e.keyCode === kendo.keys.ENTER) {            
            currentCell = $(e.target).closest('td');
            currentRow = $(e.target).closest('tr');
            cellIndex = currentCell.index();
            //debugger;
            if (cellIndex > -1) {
                grid = currentRow.closest("[data-role=grid").data("kendoGrid");                
                model = grid.dataItem(currentRow);
                if (model.isNew()) {
                    e.keyCode = kendo.keys.TAB;
                }
                else {
                    //debugger;
                    var nextRow = currentRow.next();
                    if (nextRow.length) {
                        //debugger;
                        var nextCell = nextRow.find("td").eq(cellIndex);
                        setTimeout(function () {
                            grid.closeCell(currentCell);
                            grid.current(nextCell);
                            grid.editCell(nextCell[0]);
                        }, 50);
                    }
                }
            }
        }

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 30 Oct 2015, 09:04 AM

Hello Koren,

You can get reference to the editable (the internal widget which handles the edit form) and execute its end method. This method will trigger the validation and return true or false if it pass or not.

if (grid.editable && grid.editable.end()) {
  // the edit form is valid do something here....
}

Regards,
Rosen
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Koren
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or