Leaving Grid in EDIT MODE when Using Custom errors and ModelState

4 posts, 0 answers
  1. Buddy
    Buddy avatar
    2 posts
    Member since:
    Aug 2014

    Posted 20 Apr 2015 Link to this post

    I followed the example for Ajax custom errors and server side modelstate errors, however, the grid (inline editing) goes out of Edit Mode after  my javascript error event is called.

    We would like to leave the grid in error mode.

    Not using .cancelChanges();

    // javascript 

    function grid_error(e) {
        var grid = $("#CPRProductLineGrid").data("kendoGrid");
        var knotify = $("#popupNotification").data("kendoNotification");

        if (e.errors) {
            var message = "";

            $.each(e.errors, function(key, value) {
                if ('errors' in value) {
                    $.each(value.errors, function() {
                        message += this + "<br />";
                    });
                }
            });

            knotify.show({
                title: "Validation Error",
                message: message
            }, "error");
      
           
           //grid.cancelChanges();

        }
    }

    // controller

               foreach (var item in  validator.GetValidationErrors())
                    {
                        ModelState.AddModelError("GroupCode1", item);
                    }

               return Json(ModelState.ToDataSourceResult());
  2. Rosen
    Admin
    Rosen avatar
    3253 posts

    Posted 22 Apr 2015 Link to this post

    Hi Buddy,

    In order to prevent the Grid from closing the edit form, you should handle the dataBinding event and prevent it.

    function grid_error(e) {
        var grid = $("#CPRProductLineGrid").data("kendoGrid");
        var knotify = $("#popupNotification").data("kendoNotification");
     
        if (e.errors) {
          /*...*/      
          grid.one("dataBinding", function(args) {
              args.preventDefault();
          });
     
        }
    }


    Regards,
    Rosen
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  3. Buddy
    Buddy avatar
    2 posts
    Member since:
    Aug 2014

    Posted 22 Apr 2015 in reply to Rosen Link to this post

    This does not work in 2014.3.1411 the args are ignored, the sync is fired and the edit mode always closes.
  4. Rosen
    Admin
    Rosen avatar
    3253 posts

    Posted 23 Apr 2015 Link to this post

    Hi Buddy,

    There should be no difference in the version used. Here you can find a test page which demonstrates the discussed approach. Also I have created a short video which captures the test page behavior. Please take a look maybe I'm missing something obvious.

    Regards,
    Rosen
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
Back to Top