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

Handling server side validation errors

3 Answers 119 Views
Grid
This is a migrated thread and some comments may be shown as answers.
chris
Top achievements
Rank 1
chris asked on 28 Feb 2014, 06:15 PM
I'm trying to write an event handler for server model validation errors.  Its firing and poping a message but I have a grid that im editing in batch mode.  I'd like to have the red dog ears in the upper right of the cells stay after the method presents the window to the users, but I can't get the dog ears to stay.  Heres what I'm trying:

<script type="text/javascript">
 
    function showAlertWindow(message) {
        var alertWindow = $('#alertWindow').data('kendoWindow');
        alertWindow.content(message);
        alertWindow.refresh();
        alertWindow.center();
        alertWindow.open();
    }
    function server_error_handler(event) {
        if (event.errors) {
            event.sender.one("dataBinding",function(e){
                e.preventDefault();
            });
            //event.preventDefault();
            //event.sender.cancelChanges();
            var message = "Errors:\n";
            $.each(event.errors, function (key, value) {
                if ('errors' in value) {
                    $.each(value.errors, function () {
                        message += "</br><strong>" + key + "</strong>:  " + this + " \n";
                    });
                }
            });
            message += " </br> </br> <strong>No updates were saved!</strong>";
            showAlertWindow(message);
        }
    }
 
</script>

if i uncomment and try 
//event.preventDefault();

the dog ears go away, and it looks to users as if the records were saved.....

if i uncomment and try
//event.sender.cancelChanges();

The updates are gone, the grid removes the new rows that the users tried to add which isn't what i want either, i want the grids state to be in effect unchanged, that is the content that they tried to add is still in the cells and the dog ears are still there.

How do i accomplish this?

Thanks,
Chris

3 Answers, 1 is accepted

Sort by
0
chris
Top achievements
Rank 1
answered on 28 Feb 2014, 08:18 PM
the dog ears that im referring to are the little red triangles that appear to be added by k-dirty css class.
0
chris
Top achievements
Rank 1
answered on 28 Feb 2014, 08:55 PM
So just to clarify this is like 99% of what i want but the red triangles go away, which users assume means that their content was saved.  How do i get it so the red triangles dont go away when the execution of this function completes?

function server_error_handler(event) {
        if (event.errors) {
             
            event.preventDefault();
             
            var message = "Errors:\n";
            $.each(event.errors, function (key, value) {
                if ('errors' in value) {
                    $.each(value.errors, function () {
                        message += "</br><strong>" + key + "</strong>:  " + this + " \n";
                    });
                }
            });
            message += " </br> </br> <strong>No updates were saved!</strong>";
            showAlertWindow(message);
        }
    }
0
chris
Top achievements
Rank 1
answered on 28 Feb 2014, 09:12 PM
ok solved it.  event.preventdefault(); wasn't stopping the dataBinding event.  I had to do it like this:

function server_error_handler(event) {
        if (event.errors) {
             
            var gridId = event.sender.options.table.parent('div')[0].id;
            var grid = $("#"+gridId).data("kendoGrid");
            grid.one("dataBinding", function (e) {
                e.preventDefault();
            });
             
            var message = "Errors:\n";
            $.each(event.errors, function (key, value) {
                if ('errors' in value) {
                    $.each(value.errors, function () {
                        message += "</br><strong>" + key + "</strong>:  " + this + " \n";
                    });
                }
            });
            message += " </br> </br> <strong>No updates were saved!</strong>";
            showAlertWindow(message);
        }
    }
Tags
Grid
Asked by
chris
Top achievements
Rank 1
Answers by
chris
Top achievements
Rank 1
Share this question
or