We have edit dialogs with editable fields on them, and we want to display a confirmation dialog if the user tries to close the edit dialog without saving. Simplified code to illustrate the issue:
Hello Ross,
The observed behavior (race condition) results from how Blazor events work:
I don't think there is an easy and reliable way to detect and prevent such scenarios, because the two Dialogs are completely independent of each other and they are not aware of the app business logic.
The easiest solution is to trigger a Blazor life cycle event sequence before the second confirmation Dialog shows. This will give time for the first Dialog's OnParametersSetAsync event to fire:
private async Task OnClose(bool isVisible)
{
if (!isVisible)
{
await Task.Delay(1);
var proceed = await Dialogs.ConfirmAsync("You have unsaved changes, are you sure you want to leave?");
if (!proceed)
{
return;
}
}
Visible = isVisible;
}
You will notice that now the first Dialog does not change its z-index at all, because the second Dialog is not visible yet when OnParametersSetAsync fires for the fist one, so it's still on top.
Regards,
Dimo
Progress Telerik