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
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.
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
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?
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.
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.
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.