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

Keep editing after a server side error

13 Answers 728 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Madrinha
Top achievements
Rank 1
Madrinha asked on 22 May 2013, 04:13 PM
Hello,

i want to be able to continue editing/inserting a row after a server error, and maintain the data already inserted. Is it possible? If so, how can i accomplish this?

Right now i can do some stuff on a server side error thru the event Error on DataSource, calling a user defined javascript function. I'm showing a popup with the error, but then the row exits the edition mode.

I can cancel UI changes but then i lose the data. If i don't cancel UI changes on the grid, the row is shown as if there were no errors, but it was not saved on the server.

Thanks in advance

13 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 24 May 2013, 12:31 PM
Hello Joao,

Basically when there are server side errors you can use the approach from this code library article(related to the MVC wrappers, anyway the idea remains the same).

If there is a server side error , prevent the rebinding of the Grid so the Grid remains in edit mode and the users can correct the problem.

function error(args) {       
        if (args.errors) {
            var grid = $("#Grid").data("kendoGrid");
            grid.one("dataBinding", function (e) {  
                e.preventDefault();   // cancel grid rebind if error occurs  
//...


Kind Regards,
Petur Subev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Kavitha
Top achievements
Rank 1
answered on 25 May 2016, 02:26 PM

Hi Petur,

This has stopped working in 2016.2.504. Any idea?

Thanks,

Jawad

0
Rosen
Telerik team
answered on 27 May 2016, 08:33 AM

Hello Kavitha,

Could you please provide a bit more information about what exactly does not work with the mentioned code library. I'm not able to observe any issue when the code library is modified to use the latest UI for ASP.NET MVC latest official release.

Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Kavitha
Top achievements
Rank 1
answered on 27 May 2016, 02:24 PM

Here sample from my code

    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(20)
        .Events(events =>
        {
            events.Error("kendoGridError");
        })

function kendoGridError(args, ) {
    if (args.errors) {
        var grid = $("#users").data("kendoGrid");
        grid.one("dataBinding", function (e) {
            // prevent default doesn't work in 2016.2.504
            e.preventDefault();   // cancel grid rebind if error occurs                             
        });
    }
}

e.preventDefault() doesn't prevent closing of the edit popup after I've upgraded to 2016.2.504

0
Rosen
Telerik team
answered on 30 May 2016, 08:05 AM

Hello Kavitha,

You should verify that the actual code path is hit - does the  grid.one("dataBinding", function (e) { is executed.  Also you should check if you are not manually rebinding the widget - for example by calling DataSource's read/fetch/query methods or Grid's refresh method.

If you continue to experience difficulties you should modify the Code Library project as the behavior to appear and send it back to us for further investigation.

Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Kavitha
Top achievements
Rank 1
answered on 31 May 2016, 09:39 AM

It was dataSource.read(). Fixed it now.

Thanks for your help Rosen.

0
Raj
Top achievements
Rank 1
answered on 12 Dec 2017, 04:47 PM

I updated Kendo framework to 2017.3.1026

It looks like it is not working. I am able to debug and see it is executing the code line also iam getting alert messages.

   grid.one("dataBinding", function (e) {
                e.preventDefault();   // cancel grid rebind if error occurs

                for (var error in args.errors) {
                    alert("for alert" + error);   

                }

});

0
Stefan
Telerik team
answered on 14 Dec 2017, 12:07 PM
Hello, Raj,

I updated the provided example to the 2017.3.1026 version and it is still working as expected.

I attached it for reference.

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
Raj
Top achievements
Rank 1
answered on 14 Dec 2017, 06:49 PM

Thanks for the response

I see that project is not using 2017.3.1026, it is using 2017.3.1018.

please recheck and verify.

Thanks

Raj

0
Raj
Top achievements
Rank 1
answered on 14 Dec 2017, 08:01 PM

However in the console log(e),

action in your example is shown as sync. (action:"sync")

In my project it shows as rebind. (action:"rebind") see attached images for console.log(e)

Thanks

Raj

 

0
Stefan
Telerik team
answered on 18 Dec 2017, 09:38 AM
Hello, Raj,

Thank you for the details.

The action will be "rebind" in cases if the Grid is programmatically refreshed without making any actual changes or the when the Read of the Grid is called. Ensure that an actual update operation is made when testing the scenario.

Still, the type is not directly used in this scenario and should not affect the result.

If the issue still occurs, please provide an example where the issue is reproduced and I will gladly assist.

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
Richard
Top achievements
Rank 1
answered on 02 Sep 2019, 09:43 AM

Hello,

I am also struggling with this problem in 2019.2.514.
The error function does work. The edit form remains if a server error is detected. That's nice.

However, when the button 'save' is pressed again without any changes, no server call is done and the form closes.

I understand you write 'Ensure that an actual update operation is made when testing the scenario', so can I disable the save button and enable it when someone changes a value in the edit form? Or is there another solution available?

Richard

 

 

0
Tsvetomir
Telerik team
answered on 04 Sep 2019, 05:51 AM
Hi Richard,

If you would like to disable the Save button when an error from the server-side is returned, I would recommend to disable the button in the Error event handler. After that, you would be able to subscribe to the change events of the inputs within the form. 

When a change in those inputs is present, enable the button once again. However, if you would like to make the editing more specific, you can attach the change event only to the field responsible for triggering the exception.

As per the case that the form getting closed after pressing the button twice, it is unexpected behavior. Is it possible for you to provide a sample project in which this issue could be observed?


Best regards,
Tsvetomir
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Madrinha
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Kavitha
Top achievements
Rank 1
Rosen
Telerik team
Raj
Top achievements
Rank 1
Stefan
Telerik team
Richard
Top achievements
Rank 1
Tsvetomir
Telerik team
Share this question
or