dialog - prevent users to click save more than once

Hi,

I am working with EJ1 syncfusion grid, with edit dialog template. Everything works fine..but..

Since my dialog is large, have a lot of data to save, we noticed that some of the users, during controller create execution , when DB response is slow, click second time SAVE button on the dialog. In that case we got two same records in the table.

Is that any way to prevent users to click more than once on the add dialog?

Thanks in advance.


Attachment: index_513830d4.rar

5 Replies 1 reply marked as answer

FS Farveen Sulthana Thameeztheen Basha Syncfusion Team February 5, 2021 04:40 PM UTC

Hi Enisa , 

Thanks for contacting Syncfusion Support. 

Query#:- Is that any way to prevent users to click more than once on the add dialog? 

We have achieved this requirement using ActionBegin event of the Grid. In this event, on saving the record(when requestType as save) we have disabled the Save button using disable method of the ejButton which prevents user to click the save button again. Also we have enabled the button on ActionComplete event of the Grid. 

Refer to the below code:- 

@(Html.EJ().Grid<object>("GridTarget") 
         .Datasource(ds => ds.URL("/Grid/UrlDataSource").UpdateURL("/Grid/UrlUpdate").InsertURL("/Grid/UrlInsert").RemoveURL("/Grid/UrlDelete") 
                   .Adaptor(AdaptorType.UrlAdaptor)) 
         .ClientSideEvents(Event=> Event.ActionComplete("actionComplete").ActionBegin("actionBegin")) 
         .EditSettings(edit => 
                                                            { 
                                                                edit.AllowAdding(); 
                                                                edit.AllowEditing(); 
                                                                edit.AllowDeleting(); 
                                                                edit.AllowEditOnDblClick(false); 
                                                                edit.ShowDeleteConfirmDialog(true); 
                                                                edit.EditMode(Syncfusion.JavaScript.EditMode.DialogTemplate).DialogEditorTemplateID("#targetDialog"); 
 
                                                            }) 
       .Columns(col => 
         { 
             col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add(); 
            col.Field("CustomerID").HeaderText("Customer ID").Width(80).Add(); 
                 .   .   . 
         }) 
) 
 
<script> 
    function actionComplete(args) { 
        if (args.requestType == "save") { 
            $("#EditDialog_GridTarget_Save").ejButton("enable"); //enable the save button 
        } 
    } 
 
    function actionBegin(args) { 
        if (args.requestType == "save") { 
           $("#EditDialog_GridTarget_Save").ejButton("disable"); //disable the save button ---use EditDialog_GridID here  
           
        } 
    } 
</script> 


Refer to the API Link:- 

Please get back to us if you need any further assistance. 

Regards,
Farveen sulthana T 


Marked as answer

EM Enisa Manjo February 9, 2021 10:01 AM UTC

Dear Farveen Sulthana T ,

this solution is satisfying when model is valid. But in the case when model is not valid, then the button remain disabled, what i would like to avoid. Is there any sloution available for this case?

Regards,

Enisa


FS Farveen Sulthana Thameeztheen Basha Syncfusion Team February 10, 2021 11:40 AM UTC

Hi Enisa,  

Query#:- But in the case when model is not valid, then the button remain disabled, what i would like to avoid. Is there any solution available for this case

For this scenario ,when the model is Invalid at server end, ActionFailure Clientside event get triggers. So that you can again enable the save button using enable method of ejButton with this Event and perform further actions in it. 

Refer to the code below:- 
@(Html.EJ().Grid<object>("GridTarget") 
         .Datasource(ds => ds.URL("/Grid/UrlDataSource").UpdateURL("/Grid/UrlUpdate").InsertURL("/Grid/UrlInsert").RemoveURL("/Grid/UrlDelete") 
                   .Adaptor(AdaptorType.UrlAdaptor)) 
         .ClientSideEvents(Event=> Event.ActionComplete("actionComplete").ActionBegin("actionBegin").ActionFailure("failure"))          
           
          .Columns(col => 
         { 
             col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add();         
                .   .   . 
 
}) 
) 

<script> 
 
    function failure(args) { 
        if (args.requestType == "save") { 
            $("#EditDialog_GridTarget_Save").ejButton("enable");   //enable the save button use EditDialog plus GridID here 
        } 
    } 
</script> 

Refer to the API Link:- 

Please get back to us if you need any further assistance. 

Regards, 
Farveen sulthana T 



EM Enisa Manjo February 10, 2021 12:10 PM UTC

Dear Farveen Sulthana Thameeztheen ,

on my grid I have 
          .ClientSideEvents(eve =>
                                                                        {
                                                                            eve.ActionBegin("onTargetActionBegin");
                                                                            eve.ActionComplete("onTargetActionComplete");
                                                                            eve.RowSelecting("rowSelecting");
                                                                            eve.RowDataBound("onGridTargetRowDataBound");
                                                                            eve.DataBound("onDataBound");
                                                                            eve.ActionFailure("onGridActionFailure");
                                                                        })

and in my controller 
    public ActionResult Update_Target(TargetViewModel value)
        {
            try
            {
                if (!ModelState.IsValid )
                {
                    var error = "error";
                    return BadRequest(error);
                }...
when I simulate error , the function "onGridActionFailure" never fired :(

Best regards,

Enisa


FS Farveen Sulthana Thameeztheen Basha Syncfusion Team February 11, 2021 04:12 PM UTC

Hi Enisa, 

Query#:- when I simulate error , the function "onGridActionFailure" never fired :( 

We are unable to replicate the problem at our end(ActionFailure event fired when model is invalid). Refer to the sample Link:- 

Refer to the code below:- 
GridFeatures.cshtml 
@(Html.EJ().Grid<object>("GridTarget") 
         .Datasource(ds => ds.URL("/Grid/UrlDataSource").UpdateURL("/Grid/UrlUpdate").InsertURL("/Grid/UrlInsert").RemoveURL("/Grid/UrlDelete") 
                   .Adaptor(AdaptorType.UrlAdaptor)) 
         .ClientSideEvents(Event=> Event.ActionComplete("actionComplete").ActionBegin("actionBegin").ActionFailure("failure")) 
          
                                                                edit.EditMode(Syncfusion.JavaScript.EditMode.DialogTemplate).DialogEditorTemplateID("#targetDialog"); 
 
      .Columns(col => 
         { 
             col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add(); 
            .  .   . 
        }) 
) 

Serverside:- 
GridController.cs 
      public ActionResult UrlUpdate(Orders value) 
        { 
            if (!ModelState.IsValid) //if validation got failed 
            { 
                var message = string.Join(" | ", ModelState.Values 
                     .SelectMany(v => v.Errors) 
                      .Select(e => e.ErrorMessage)); 
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest, message);//message returns the exception content  
            } 
            var ord = value; 
            Orders val = order.Where(or => or.OrderID == ord.OrderID).FirstOrDefault(); 
              .  .   . 
            return Json(value, JsonRequestBehavior.AllowGet); 
        } 
 
        public ActionResult UrlInsert(Orders value) 
        { 
            if (!ModelState.IsValid) //if validation got failed 
             { 
                var message = string.Join(" | ", ModelState.Values 
                     .SelectMany(v => v.Errors) 
                      .Select(e => e.ErrorMessage)); 
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest, message);//message returns the exception content  
            } 
             
            order.Insert(0, value); 
            string msg = "Successfully performed editing the record"; 
            return Json(new { value = value, message = msg }); 
 
        } 
 
        [Serializable] 
        public class Orders 
        { 
             
            public long OrderID { get; set; } 
            
            [MinLength(3)] 
            public string CustomerID { get; set; } 
            public DateTime? OrderDate { get; set; } 
 
             
        } 


Note- Grid has been placed under Views->Grid/GridFeatures.cshtml page 

Screenshot:- 
 

We need some more additional details to find the cause of the issue. Share us the following details. 

  1. Complete Grid code details(both client and server end).
  2. If possible replicate the problem in the above sample and revert us back.
  3. Screenshot/Video Demo to replicate the issue.
  4. Product version details.

Regards,
Farveen sulthana T 


Loader.
Up arrow icon