Autocomplete
See original GitHub issueHello,
I’m trying to use the Autocomplete component. I’m getting a the selected value from the parent component and the list to filter from an external service. I’m use blazor server. When the component load it didn’t display the display value, it didn’t go to the ToStringFunc when i’m in debug.
Do you see something wrong or it’s a bug on the autocomple
Thanks in advance for you help.
Please find the code below :
<MudAutocomplete T="ExternalList" Variant="Variant.Outlined" Margin="Margin.Dense" Label="Kizeo external list" SearchFunc="@Search2" @bind-Value="SelectedExternalList" ToStringFunc="@((e)=>@ToString(e))"/>
private ExternalList _selectedExternalList;
private List<ExternalList> _externalList = new();
[Inject] private IGetExternalListsService GetExternalListsService { get; set; }
private string _kizeoExternalListId;
[Parameter]
public string KizeoExternalListId
{
get => _kizeoExternalListId;
set
{
if (_kizeoExternalListId == value) return;
_kizeoExternalListId = value;
KizeoExternalListIdChanged.InvokeAsync(value);
}
}
[Parameter] public EventCallback<string> KizeoExternalListIdChanged { get; set; }
private string _kizeoExternalListName;
[Parameter]
public string KizeoExternalListName
{
get => _kizeoExternalListName;
set
{
if (_kizeoExternalListName == value) return;
_kizeoExternalListName = value;
KizeoExternalListNameChanged.InvokeAsync(value);
}
}
[Parameter] public EventCallback<string> KizeoExternalListNameChanged { get; set; }
private ExternalList SelectedExternalList
{
get => _selectedExternalList;
set
{
if (_selectedExternalList == value) return;
KizeoExternalListId = value.Id;
KizeoExternalListName = value.Name;
_selectedExternalList = value;
}
}
public string ToString(ExternalList el)
{
if (el == null)
{
return null;
}
return el.Name;
}
protected override async Task OnInitializedAsync()
{
_externalList = (await GetExternalListsService.GetAll()).ToList();
}
protected override void OnParametersSet()
{
var matchingFormLight = _externalList.SingleOrDefault(t => t.Id == _kizeoExternalListId);
if (matchingFormLight != null)
{
SelectedExternalList = matchingFormLight; StateHasChanged();
};
}
private async Task<IEnumerable<ExternalList>> Search2(string value)
{
await Task.Delay(5);
if (string.IsNullOrEmpty(value))
return _externalList;
return _externalList.Where(x => x.Name.Contains(value, StringComparison.InvariantCultureIgnoreCase));
}
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (8 by maintainers)
Top Results From Across the Web
Manage Google autocomplete predictions - Android
With autocomplete, you can enter a Google search more quickly. You can turn off or remove certain autocomplete predictions or report issues with...
Read more >HTML attribute: autocomplete - MDN Web Docs
The HTML autocomplete attribute lets web developers specify what if any permission the user agent has to provide automated assistance in ...
Read more >Autocomplete - Wikipedia
Autocomplete, or word completion, is a feature in which an application predicts the rest of a word a user is typing. In Android...
Read more >Autocomplete | jQuery UI
Autocomplete. Enables users to quickly find and select from a pre-populated list of values as they type, leveraging searching and filtering. Examples.
Read more >React Autocomplete component - Material UI
The autocomplete is a normal text input enhanced by a panel of suggested options. The widget is useful for setting the value of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I have the same issue, whenever I try to set the value with a delay it won’t show the selected value. But focusing the input then click outside it will show the correct selected value and then refocus the element.
Here my snippet if it could help: https://try.mudblazor.com/snippet/QkcvayanKcmhgHGT
fixed