Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,617 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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)
{
//
}
}
It may be that the debounce interval is too short, and what would happen is that the value is reset when the search function is activated. Have you tried increasing the value to DebounceInterval="1000" or more?
<MudAutocomplete T="ItemResponse"
Label="AutoComplete"
SearchFunc="@OnComboSearch"
Value="selecteditemResponse"
ValueChanged="OnComboValueChanged"
ResetValueOnEmptyText="true"
DebounceInterval="1000" />
Regards,