BzAutoComplete
AutoComplete
Smart search over a static list or an async source.
ButtonsFormsInput groupButton groupsDatePickerAutoCompleteCardsDisplayLoadingDialogsNotificationsOperation messageDrawerContext menuPaginationLightboxTreeDataGridChartsTabs & AccordionNavigationSidebarTimelineWizardCarouselUploaderEditorCalendarIranian tools
No component found.
Static list
The simplest way is to pass a list, for example, a city or province list, to it.
city=
@using BzCore.Components.AutoComplete
<BzAutoComplete TItem="string"
@bind-Value="_city"
Label="شهر"
Items="_cities"
Clearable
Placeholder="جستجوی شهر" />
<p>city=@_city</p>
@code {
private string _city = "";
private readonly string[] _cities =
{
"تهران", "مشهد", "اصفهان", "شیراز", "تبریز",
"کرج", "اهواز", "قم", "کرمانشاه", "رشت"
};
}Async search
In this approach, you can bind a method instead of a static list to perform live searches directly against an API. Additionally, you can use `debounceMs` to manage input delays while typing.
async=
| Parameter | Description |
|---|---|
Items | The primary data, such as a list of cities, is something you have already fetched from the server and now want to pass to the component. |
SearchFunc | Instead of using `items`, you attach a method, so requests are sent directly to the server as the user types and the search is performed there. |
MinSearchLength | Minimum number of characters required to start searching. |
DebounceMs | Delay between typing and searching |
Clearable | Shows a clear button |
@using BzCore.Components.AutoComplete
<BzAutoComplete TItem="string"
@bind-Value="_city"
Label="شهر (async)"
SearchFunc="SearchCitiesAsync"
MinSearchLength="1"
DebounceMs="250"
Placeholder="حداقل 1 حرف" />
<p>async=@_city</p>
@code {
private string _city = "";
private readonly string[] _all =
{
"تهران", "مشهد", "اصفهان", "شیراز", "تبریز",
"کرج", "اهواز", "قم", "کرمانشاه", "رشت"
};
// Swap this body for a real API / EF Core call.
private async Task<IEnumerable<string>> SearchCitiesAsync(string term)
{
await Task.Delay(150); // pretend network latency
return _all.Where(c => c.Contains(term, StringComparison.OrdinalIgnoreCase));
}
}