Add autocomplete for account
This commit is contained in:
parent
ff075be32d
commit
a45495c296
2 changed files with 28 additions and 10 deletions
|
|
@ -1,7 +1,9 @@
|
|||
<select @bind="@AccountId" @oninput="OnInputChanged">
|
||||
<option value=""></option>
|
||||
@foreach (var account in Accounts.OrderBy(a => a.Number).ThenBy(a => a.Name))
|
||||
{
|
||||
<option value="@account.Id">@($"{account.Number} / {account.Name}")</option>
|
||||
}
|
||||
</select>
|
||||
<FluentAutocomplete TOption="Account"
|
||||
AutoComplete="off"
|
||||
Autofocus="true"
|
||||
MaxAutoHeight="true"
|
||||
OnOptionsSearch="@OnSearchAsync"
|
||||
MaximumSelectedOptions="1"
|
||||
OptionText="@(account => $"{account.Number} / {account.Name}")"
|
||||
SelectedOptionsChanged="OnSelectedChanged"
|
||||
ValueText="@(SelectedAccount?.Name)"/>
|
||||
|
|
@ -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<Account> Accounts { get; set; }
|
||||
|
||||
[Parameter] public EventCallback<string> 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<Account> 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<Account>? s)
|
||||
{
|
||||
SelectedAccount = s?.FirstOrDefault();
|
||||
AccountId = SelectedAccount?.Id;
|
||||
await AccountIdChanged.InvokeAsync(AccountId);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue