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

Handling Errors on Insert (Pop-up Edit form)

10 Answers 647 Views
Grid
This is a migrated thread and some comments may be shown as answers.
AP
Top achievements
Rank 1
Iron
Iron
Veteran
AP asked on 01 Feb 2013, 12:04 PM
I've got a grid, with a pop-up edit form, where there is some controller level validation applied before the record is saved.

The grid is defined:-
@(Html.Kendo().Grid<CMS_2013.Models.SeasonalProfile>()
.Name("Grid")
.Events(e=>e.Edit("onEdit"))
.Columns(columns=>
{
 
    columns.Bound(o => o.ID);
    columns.Bound(o => o.Profile_Code);
    columns.Bound(o => o.ProfileType);
    columns.Bound(o => o.Description);
    columns.Bound(o => o.Site);
    columns.Bound(o => o.PATCLASS);
    columns.Bound(o => o.Specialty);
     
    columns.Command(command => { command.Edit(); command.Destroy(); });
 
      
    })
  .ToolBar(commands=>commands.Create())
   .Editable(editable=>editable
        .Mode(GridEditMode.PopUp))
 
 
    .DataSource(dataSource=>dataSource
        .Ajax()
        .Model(m=>m.Id(p=>p.ID))
        .Events(events => events.Error("error"))
        .PageSize(10)
         
         
        .Read(read=>read.Action("ReadProfiles","Profiles"))
        .Create(create=>create.Action("InsertProfile","Profiles"))
        .Update(update=>update.Action("UpdateProfile","Profiles"))
        .Destroy(delete=>delete.Action("DeleteProfile","Profiles"))
        )
        .Pageable()
        .Sortable()
        .Filterable()
   
       )
The error handler is:-
function error(e) {
       if (e.errors) {
           var message = "Errors:\n";
           $.each(e.errors, function (key, value) {
               if ('errors' in value) {
                   $.each(value.errors, function () {
                       message += this + "\n";
                   });
               }
           });
 
 
           alert(message);
          
       }
 
   }

This works fine, displaying the error message if the validation fails. However, I have two problems:-

  1. After displaying the alert, the edit form is closed, so the user can't correct their error - they have to start all over again
  2. Even though the record hasn't been saved - a new record is displayed in the grid, and only after refreshing the grid does it disappear.

How can I solve these two issues?

Thanks

10 Answers, 1 is accepted

Sort by
0
Accepted
Dimiter Madjarov
Telerik team
answered on 01 Feb 2013, 05:23 PM
Hello Andrew,

 
Please take a look at this code library about Handling server-side validation errors during pop-up editing. It covers a case, similar to yours.

Let me know if this solves your issue.

Greetings,
Dimiter Madjarov
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
AP
Top achievements
Rank 1
Iron
Iron
Veteran
answered on 04 Feb 2013, 08:57 AM
Thanks for this.

Using the error code as per the example, it stopped the edit form closing, but no message was displayed.

So I just altered my original code to:-

function error(e) {
       if (e.errors) {
 
           
 
 
           var message = "Errors:\n";
           $.each(e.errors, function (key, value) {
               if ('errors' in value) {
                   $.each(value.errors, function () {
                       message += this + "\n";
                   });
               }
           });
 
           var grid = $("#Grid").data("kendoGrid");
           grid.one("dataBinding", function (e) {
               e.preventDefault();   // cancel grid rebind if error occurs  
           });
 
 
           alert(message);
          
       }
 
   }
This works fine now.
0
Oliver
Top achievements
Rank 1
answered on 11 Apr 2016, 04:57 PM
This no longer works. It still closes the popup. What can I do to prevent this now?
0
Dimiter Madjarov
Telerik team
answered on 12 Apr 2016, 01:40 PM

Hello Oliver,

We are not aware of issues with the mentioned approach. You could find the example with a more recent Kendo UI version on the following documentation page.

Regards,
Dimiter Madjarov
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
0
Oliver
Top achievements
Rank 1
answered on 19 Apr 2016, 08:44 AM

OK, I figured out the reason. I had this code in addition:

 

function onGridDataSourceRequestEnd(e) {
    if (e.type == "update" || e.type == "create") {
       // this.read();
    }
}

 

Removing it, keeps the popup open

0
Dimiter Madjarov
Telerik team
answered on 19 Apr 2016, 03:00 PM

Hello Oliver,

Thanks for the update.

Regards,
Dimiter Madjarov
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
0
Graham
Top achievements
Rank 1
answered on 05 May 2017, 12:18 PM

Hi

I am trying to follow the example Handling server-side validation errors during pop-up editing UI for ASP.NET MVC Resources.

In the example the error relates to a specific field.  I would like to use a kendo notification in the error style if for example a record has been deleted that another user is trying to edit.  For example "Record no longer exists".  

I have an example on a change password form but I cannot replicate it on a grid popup editor.

0
Preslav
Telerik team
answered on 09 May 2017, 12:16 PM
Hi Graham,

A possible solution might be using a custom popup editor for the grid.

http://docs.telerik.com/aspnet-mvc/helpers/grid/how-to/editing/custom-popup-editor

In the popup, based on a condition you could display the notification. I believe that these examples could assist you in implementing this functionality:

http://demos.telerik.com/aspnet-mvc/notification/templates

Regards,
Preslav
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Ed
Top achievements
Rank 1
answered on 07 Oct 2018, 01:34 AM

I got the same problem as Oliver.

The line "this.read" has been commented out.

When are you going to refresh the grid after insertion or edition?

Edmond

0
Preslav
Telerik team
answered on 09 Oct 2018, 10:01 AM
Hi Edmond,

The Grid could be refreshed in many different scenarios. One of them is when the user hits the update button when editing a record. 

Could you please elaborate on your scenario? This will help me in providing assistance to the best of my knowledge.


Regards,
Preslav
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
AP
Top achievements
Rank 1
Iron
Iron
Veteran
Answers by
Dimiter Madjarov
Telerik team
AP
Top achievements
Rank 1
Iron
Iron
Veteran
Oliver
Top achievements
Rank 1
Graham
Top achievements
Rank 1
Preslav
Telerik team
Ed
Top achievements
Rank 1
Share this question
or