The text is getting cleared in MudBlazor Autocomplete component

Buddhi - BLUE LOTUS 360 1 Reputation point
2023-04-18T15:28:31.9866667+00:00

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)
    {
       //
    }

}

Blazor
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
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,108 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Osjaetor 480 Reputation points
    2023-06-05T19:21:22.8366667+00:00

    Hi Buddhi - BLUE LOTUS 360,

    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,

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.