Hello @Content.Firstname
Your lastname is @Content.Lastname and you are @Content.Age years young
@@ -12,4 +14,4 @@
@code {
[Parameter]
public SimplePerson Content { get; set; } = default!;
-}
\ No newline at end of file
+}
diff --git a/examples/Demo/Shared/Pages/Panel/PanelPage.razor b/examples/Demo/Shared/Pages/Panel/PanelPage.razor
index faf759c461..c721627a72 100644
--- a/examples/Demo/Shared/Pages/Panel/PanelPage.razor
+++ b/examples/Demo/Shared/Pages/Panel/PanelPage.razor
@@ -52,6 +52,14 @@
+
+
+ The panel that is anchored to the right side of the screen can be dismissed by clicking the dismiss button (at the top),
+ 'No' button (at the bottom) or 'Yes' button (at the bottom).
+ Before the panel is closed, it will validate the data and, if not ok, will prevent the dialog from closing using the 'Yes' button.
+
+
+
Documentation
diff --git a/src/Core/Components/Dialog/FluentDialog.razor.cs b/src/Core/Components/Dialog/FluentDialog.razor.cs
index 2efbed4b19..f4caa3cd03 100644
--- a/src/Core/Components/Dialog/FluentDialog.razor.cs
+++ b/src/Core/Components/Dialog/FluentDialog.razor.cs
@@ -241,6 +241,16 @@ public async Task CloseAsync(DialogResult dialogResult)
{
await Instance.Parameters.OnDialogClosing.InvokeAsync(Instance);
}
+
+ if (Instance.Parameters.ValidateDialogAsync != null && !dialogResult.Cancelled)
+ {
+ var isValid = await Instance.Parameters.ValidateDialogAsync();
+
+ if (!isValid)
+ {
+ return;
+ }
+ }
}
DialogContext?.DialogContainer.DismissInstance(Id!, dialogResult);
if (Instance is not null)
diff --git a/src/Core/Components/Dialog/Parameters/DialogParameters.cs b/src/Core/Components/Dialog/Parameters/DialogParameters.cs
index 166e0d4615..78aee66286 100644
--- a/src/Core/Components/Dialog/Parameters/DialogParameters.cs
+++ b/src/Core/Components/Dialog/Parameters/DialogParameters.cs
@@ -167,6 +167,14 @@ public virtual HorizontalAlignment Alignment
/// This method is only called when using the .
///
public EventCallback OnDialogOpened { get; set; } = default!;
+
+ ///
+ /// Function that is called and awaited before the dialog is closed.
+ ///
+ ///
+ /// This is a suitable callback to use when you need to validate the data in the dialog before it closes.
+ ///
+ public Func> ValidateDialogAsync { get; set; } = default!;
}
///