Keydown Handler with Invalid Cell

2 posts, 0 answers
  1. Koren
    Koren avatar
    68 posts
    Member since:
    Oct 2010

    Posted 27 Oct 2015 Link to this post

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

  2. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 30 Oct 2015 Link to this post

    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
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top