question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hello,

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:closed
  • Created 3 years ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
Vixyscommented, Apr 3, 2021

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

0reactions
henoncommented, Apr 17, 2021

fixed

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found