We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Prevent EditDialog from closing on ActionFailure

Hi,

Is it possible to prevent the edit dialog from closing when an action failure occurs, I have some validations that happen server side.


The action fails as it should, but I would like the form to stay open and filled.


Many thanks


5 Replies 1 reply marked as answer

MS Monisha Saravanan Syncfusion Team November 29, 2022 01:00 PM UTC

Hi Alexandre,


Greetings from Syncfusion support.


We would like to inform that by setting args.cancel as true will prevent the dialog from closing. You can enable this in ActionEvents after ActionFailure occurs. Kindly check the attached code snippet and documentation for your reference.


public async Task ActionBegin(ActionEventArgs<Order> args)

    {

       

        if(args.RequestType == Syncfusion.Blazor.Grids.Action.Save && IsSave)

        {

            args.Cancel = true;

           

           

 

        }

 

    }


Reference: https://blazor.syncfusion.com/documentation/datagrid/events#onactionbegin


If the reported issue still reproduced then kindly share the below details to validate further at our end.


  1. Share us the entire Grid code snippet along with model class.
  2. Share us the video demonstration of the reported issue.
  3. If possible kindly share us the simple issue reproduceable sample.


The above-requested details will be very helpful for us to validate the reported query at our end and provide the solution as early as possible.


Regards,

Monisha



AP Alexandre Pereira November 29, 2022 11:49 PM UTC

Hi,


Thanks for the quick response.


I thought it would solve my issue however the BeginEvent is fired before the ActionFailure event meaning I don't know if I need to prevent the form from closing or no. Is there a way to cancel it from the ActionFailure event?



MS Monisha Saravanan Syncfusion Team November 30, 2022 12:39 PM UTC


Hi Alexandre,


We suspect that you have handled some operation on server side and you are expecting to prevent dialog when ActionFailure is triggered. If so we suggest you to handle your own customized button for save and cancel and after checking the ActionFailure event and we suggest you to Save/Cancel by performing CloseEdit/EndEdit methods. Kindly check the attached code snippet for your reference.



<SfGrid @ref=Grid DataSource="@Orders" AllowPaging="true" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })" Height="315">

  <GridEvents OnActionComplete="ActionComplete" OnActionBegin="ActionBegin" TValue ="Order"></GridEvents>

   <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Dialog">

        <HeaderTemplate>

         Text

        </HeaderTemplate>

        

        <FooterTemplate>

<SfButton OnClick="Save">Save</SfButton>

                <SfButton OnClick="Cancel">Cancel</SfButton>

        </FooterTemplate>

    </GridEditSettings>

</SfGrid>

 

@code{

 

    public async Task Save()

    {

         await Grid.ShowSpinnerAsync();

        await Grid.EndEditAsync();

     

    }

    public async Task Cancel()

    {

      

        await Grid.CloseEditAsync();

    }

    public async Task ActionBegin(ActionEventArgs<Order> args)

 

    {

 

       if((args.RequestType == Syncfusion.Blazor.Grids.Action.Save))

 

        {

 

            await Grid.ShowSpinnerAsync();

 

        }

 

    }

}



EndEditAsync - If Grid is in editable state, you can save a record by invoking endEdit.

CloseEditAsync - Cancels edited state.


Please let us know if you have any concerns.



AP Alexandre Pereira November 30, 2022 11:25 PM UTC

Hi Monisha,


Thanks a lot for your answer.


I don't really understand how this would help me, I am just trying to check if the POST or PUT request throw an exception, if so, just prevent the dialog from closing.


I have attached the page and code behind; it might be easier to understand what I want to achieve.


Attachment: syncfusion_sample_2e3bc0a4.zip


MS Monisha Saravanan Syncfusion Team December 1, 2022 12:42 PM UTC


Hi Alexandre,


We have checked your code snippet and we suspect that the Action failure will be triggered once we click save/cancel button and you are expecting to prevent the closing of dialog after clicking cancel/save button. If so we would like to inform that it is impossible to prevent closing the dialog once the EndEdit(save)/CloseEdit(cancel) is called.


Please let us know if you have further queries.


Marked as answer
Loader.
Up arrow icon