-
Notifications
You must be signed in to change notification settings - Fork 383
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 provided by the user (#2614) * [Dialog] Add event before closing panel to allow validation of the data. (#1508) * [Dialog] Add event before closing panel to allow validation of the data. (#1508) * [Dialog] Add event before closing panel to allow validation of the data. (#1508) * Rename OnDialogValidation to ValidateDialogAsync Renamed the property OnDialogValidation to ValidateDialogAsync across multiple files in the Microsoft.FluentUI.AspNetCore.Components library. Updated the member name in the XML documentation, and modified the property assignments and invocations in DialogPanelWithValidation.razor.cs, FluentDialog.razor.cs, and DialogParameters.cs to reflect this change. --------- Co-authored-by: Vincent Baaij <[email protected]>
- Loading branch information
1 parent
784d17c
commit e45f906
Showing
7 changed files
with
103 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> |
60 changes: 60 additions & 0 deletions
60
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,60 @@ | ||
// ------------------------------------------------------------------------ | ||
// 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, | ||
ValidateDialogAsync = async () => | ||
{ | ||
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; | ||
}); | ||
} | ||
|
||
await Task.Delay(100); | ||
|
||
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