I am working on the Blazor web assembly project which is running on .net7 and using MudBlazor (version-6.0.10) as the UI framework. so I have created a custom autocomplete component in MudBlazor.
then my issue is the text that I type on this autocomplete is getting cleared automatically while searching/typing
following you can see that razor component.
<MudAutocomplete T="ItemResponse"
Label="AutoComplete"
SearchFunc="@OnComboSearch"
Value="selecteditemResponse"
ValueChanged="OnComboValueChanged"
ResetValueOnEmptyText="true" DebounceInterval="700"/>
@code{
private ItemResponse selecteditemResponse = new ItemResponse();
IList<ItemResponse> ItemRes = new List<ItemResponse>();
private bool IsServerFiltering =true;
protected override async Task OnInitializedAsync()
{
await ReadAutoCompleteData();
await base.OnInitializedAsync();
}
protected override Task OnParametersSetAsync(){}
private async Task<IEnumerable<ItemResponse>> OnComboSearch(string value)
{
if (string.IsNullOrEmpty(value))
{
selecteditemResponse = new ItemResponse();
return ItemRes;
}
if (IsServerFiltering)
{
await ReadAutoCompleteData(value);
}
return ItemRes.Where(x => x.ItemName!=null && x.ItemName.Contains(value, StringComparison.InvariantCultureIgnoreCase));
}
public async Task ReadAutoCompleteData(string SearchQuery="")
{
ComboRequestDTO requestDTO = new ComboRequestDTO();
requestDTO.SearchQuery = SearchQuery;
ItemRes = await _comboManager.GetItemResponses(requestDTO);//api call
/*here i am getting the data for this autocomplete through an api call and assign it to a ItemRes list
(normally we are getting more than 3000 items for this combo if SearchQuery string is null or empty
otherwise only 10 records are coming)*/
}
private async Task OnComboValueChanged(ItemResponse itemResponse)
{
//
}
}