-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Dialog] Add event before closing panel to allow validation of the da…
…ta. (#1508)
- Loading branch information
1 parent
84170b5
commit afaffe0
Showing
7 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
examples/Demo/Shared/Pages/Panel/Examples/DialogPanelWithValidation.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@inject IDialogService DialogService | ||
@inject IMessageService MessageService | ||
|
||
<FluentButton @onclick="@OpenPanelRightAsync" Appearance="Appearance.Accent"> | ||
Open panel (>>) | ||
</FluentButton> |
58 changes: 58 additions & 0 deletions
58
examples/Demo/Shared/Pages/Panel/Examples/DialogPanelWithValidation.razor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// ------------------------------------------------------------------------ | ||
// MIT License - Copyright (c) Microsoft Corporation. All rights reserved. | ||
// ------------------------------------------------------------------------ | ||
|
||
using FluentUI.Demo.Shared.SampleData; | ||
using Microsoft.FluentUI.AspNetCore.Components; | ||
|
||
namespace FluentUI.Demo.Shared.Pages.Panel.Examples; | ||
public partial class DialogPanelWithValidation | ||
{ | ||
private IDialogReference? _dialog; | ||
|
||
private readonly SimplePerson simplePerson = new() | ||
{ | ||
Firstname = "Steve", | ||
Lastname = "Roth", | ||
Age = 42, | ||
}; | ||
|
||
private async Task OpenPanelRightAsync() | ||
{ | ||
DemoLogger.WriteLine($"Open right panel"); | ||
|
||
MessageService.Clear(); | ||
|
||
_dialog = await DialogService.ShowPanelAsync<SimplePanel>(simplePerson, new DialogParameters<SimplePerson>() | ||
{ | ||
Content = simplePerson, | ||
Alignment = HorizontalAlignment.Right, | ||
Title = $"Hello {simplePerson.Firstname}", | ||
PrimaryAction = "Yes", | ||
SecondaryAction = "No", | ||
PreventDismissOnOverlayClick = true, | ||
OnDialogValidation = () => | ||
{ | ||
var result = simplePerson.Firstname.Length > 0 && simplePerson.Lastname.Length > 0; | ||
if (!result) | ||
{ | ||
DemoLogger.WriteLine("Panel cannot be closed because of validation errors."); | ||
MessageService.ShowMessageBar(options => | ||
{ | ||
options.Intent = MessageIntent.Error; | ||
options.Title = "Validation error"; | ||
options.Body = "First name and last name cannot be empty"; | ||
options.Timestamp = DateTime.Now; | ||
options.Section = App.MESSAGES_DIALOG; | ||
}); | ||
} | ||
return result; | ||
} | ||
}); | ||
|
||
DialogResult result = await _dialog.Result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters