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">
|
<FluentAutocomplete TOption="Account"
|
||||||
<option value=""></option>
|
AutoComplete="off"
|
||||||
@foreach (var account in Accounts.OrderBy(a => a.Number).ThenBy(a => a.Name))
|
Autofocus="true"
|
||||||
{
|
MaxAutoHeight="true"
|
||||||
<option value="@account.Id">@($"{account.Number} / {account.Name}")</option>
|
OnOptionsSearch="@OnSearchAsync"
|
||||||
}
|
MaximumSelectedOptions="1"
|
||||||
</select>
|
OptionText="@(account => $"{account.Number} / {account.Name}")"
|
||||||
|
SelectedOptionsChanged="OnSelectedChanged"
|
||||||
|
ValueText="@(SelectedAccount?.Name)"/>
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
|
using Microsoft.FluentUI.AspNetCore.Components;
|
||||||
using Schaad.Accounting.Models;
|
using Schaad.Accounting.Models;
|
||||||
|
|
||||||
namespace Schaad.Accounting.UI.Components.Pages.Controls;
|
namespace Schaad.Accounting.UI.Components.Pages.Controls;
|
||||||
|
|
@ -11,9 +12,24 @@ public partial class AccountSelector : ComponentBase
|
||||||
|
|
||||||
[Parameter] public EventCallback<string> AccountIdChanged { get; set; }
|
[Parameter] public EventCallback<string> AccountIdChanged { get; set; }
|
||||||
|
|
||||||
private async Task OnInputChanged(ChangeEventArgs e)
|
private Account? SelectedAccount { get; set; }
|
||||||
|
|
||||||
|
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);
|
await AccountIdChanged.InvokeAsync(AccountId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue