From a45495c2960fe7b92a27d0bf2ae6dac0ed9c2125 Mon Sep 17 00:00:00 2001 From: Claudio Schaad Date: Thu, 15 May 2025 22:01:48 +0200 Subject: [PATCH] Add autocomplete for account --- .../Pages/Controls/AccountSelector.razor | 16 ++++++++------ .../Pages/Controls/AccountSelector.razor.cs | 22 ++++++++++++++++--- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/Schaad.Accounting.UI/Components/Pages/Controls/AccountSelector.razor b/Schaad.Accounting.UI/Components/Pages/Controls/AccountSelector.razor index dcbef09..37fa8b1 100644 --- a/Schaad.Accounting.UI/Components/Pages/Controls/AccountSelector.razor +++ b/Schaad.Accounting.UI/Components/Pages/Controls/AccountSelector.razor @@ -1,7 +1,9 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/Schaad.Accounting.UI/Components/Pages/Controls/AccountSelector.razor.cs b/Schaad.Accounting.UI/Components/Pages/Controls/AccountSelector.razor.cs index 900ff6c..8fac290 100644 --- a/Schaad.Accounting.UI/Components/Pages/Controls/AccountSelector.razor.cs +++ b/Schaad.Accounting.UI/Components/Pages/Controls/AccountSelector.razor.cs @@ -1,7 +1,8 @@ using Microsoft.AspNetCore.Components; +using Microsoft.FluentUI.AspNetCore.Components; using Schaad.Accounting.Models; -namespace Schaad.Accounting.UI.Components.Pages.Controls; +namespace Schaad.Accounting.UI.Components.Pages.Controls; public partial class AccountSelector : ComponentBase { @@ -10,10 +11,25 @@ public partial class AccountSelector : ComponentBase [Parameter] public required IReadOnlyList Accounts { get; set; } [Parameter] public EventCallback AccountIdChanged { get; set; } + + private Account? SelectedAccount { get; set; } - private async Task OnInputChanged(ChangeEventArgs e) + protected override void OnInitialized() { - AccountId = e.Value?.ToString(); + SelectedAccount = Accounts.FirstOrDefault(account => account.Id == AccountId); + } + + private async Task OnSearchAsync(OptionsSearchEventArgs e) + { + e.Items = Accounts.Where(i => i.Name.Contains(e.Text, StringComparison.OrdinalIgnoreCase)) + .OrderBy(i => i.Name); + await Task.CompletedTask; + } + + public async Task OnSelectedChanged(IEnumerable? s) + { + SelectedAccount = s?.FirstOrDefault(); + AccountId = SelectedAccount?.Id; await AccountIdChanged.InvokeAsync(AccountId); } } \ No newline at end of file