Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocomplete: The selected value is not displayed. #4701

Closed
realLiangshiwei opened this issue Mar 29, 2023 · 3 comments
Closed

Autocomplete: The selected value is not displayed. #4701

realLiangshiwei opened this issue Mar 29, 2023 · 3 comments
Assignees
Labels
Status : Finished Finished work on issue, to be closed (merge/review pending, etc...) Type: Bug 🐞 Something isn't working
Milestone

Comments

@realLiangshiwei
Copy link

realLiangshiwei commented Mar 29, 2023

Describe the bug

When the selected value has a value, the component will not display the selected value.

A clear and concise description of what the bug is.

To Reproduce

Version: 1.2.0

<Autocomplete TItem="Country"
              TValue="string"
              Data="@Countries"
              TextField="@(( item ) => item.Name)"
              ValueField="@(( item ) => item.Iso)"
              @bind-SelectedValue="@selectedSearchValue"
              @bind-SelectedText="selectedAutoCompleteText"
              Filter="AutocompleteFilter.StartsWith">
    <NotFoundContent> Sorry... @context was not found! :( </NotFoundContent>
</Autocomplete>

<Field Horizontal>
    <FieldBody ColumnSize="ColumnSize.Is12">
        Selected search value: @selectedSearchValue
    </FieldBody>
    <FieldBody ColumnSize="ColumnSize.Is12">
        Selected text value: @selectedAutoCompleteText
    </FieldBody>
</Field>
@code {
    
    public class Country
    {
        public string Name { get; set; }
        public string Iso { get; set; }
    }
    
    public IEnumerable<Country> Countries;

    protected override async Task OnInitializedAsync()
    {
        Countries = new List<Country>()
        {
            new Country()
            {
                Iso = "AF",
                Name = "Afghanistan"
            },
            new Country()
            {
                Iso = "AX",
                Name = "Åland Islands"
            }
        };
        await base.OnInitializedAsync();
    }

    public string selectedSearchValue { get; set; } = "AF";
    public string selectedAutoCompleteText { get; set; } = "Afghanistan";
}

image

Expected behavior

The value should be displayed.

@realLiangshiwei realLiangshiwei added the Type: Bug 🐞 Something isn't working label Mar 29, 2023
@Aragas
Copy link

Aragas commented Mar 29, 2023

Good to know that's I'm not the only one experiencing this!
Also occurs on v1.2.1 and v1.2.2

@guillaumebaril
Copy link

Same issue.

@David-Moreira
Copy link
Contributor

Hello @realLiangshiwei
The following code works:

<Autocomplete TItem="Country"
              TValue="string"
              Data="@Countries"
              TextField="@(( item ) => item.Name)"
              ValueField="@(( item ) => item.Iso)"
              @bind-SelectedValue="@selectedSearchValue"
              @bind-SelectedText="@selectedAutoCompleteText"
              Filter="AutocompleteFilter.StartsWith">
    <NotFoundContent> Sorry... @context was not found! :( </NotFoundContent>
</Autocomplete>

<Field Horizontal>
    <FieldBody ColumnSize="ColumnSize.Is12">
        Selected search value: @selectedSearchValue
    </FieldBody>
    <FieldBody ColumnSize="ColumnSize.Is12">
        Selected text value: @selectedAutoCompleteText
    </FieldBody>
</Field>
@code {

    public class Country
    {
        public string Name { get; set; }
        public string Iso { get; set; }
    }

    public IEnumerable<Country> Countries;

    protected override async Task OnInitializedAsync()
    {
        Countries = new List<Country>()
        {
            new Country()
            {
                Iso = "AF",
                Name = "Afghanistan"
            },
            new Country()
            {
                Iso = "AX",
                Name = "Åland Islands"
            }
        };
        await base.OnInitializedAsync();
    }

    public string selectedSearchValue { get; set; } = "AF";
    public string selectedAutoCompleteText { get; set; }
}

You do not need to set both properties.
Basically don't set one or the other. In the example I didn't set selectedAutoCompleteText and Autocomplete will sync it up for you.
image

Basically when having both SelectedValue and SelectedText Autocomplete has to do work to try and figure out how it should sync, i.e value has been changed, it needs to sync text, and vice-versa. By setting only one one of the properties Autocomplete knows how/what to sync.

This should at least get you going.

I will investigate nonetheless, the problem with setting both properties simultaneously if they are the same item.

@David-Moreira David-Moreira added the Status : Finished Finished work on issue, to be closed (merge/review pending, etc...) label Mar 31, 2023
@stsrki stsrki added this to the 1.2 support milestone Apr 4, 2023
@stsrki stsrki closed this as completed Apr 4, 2023
@stsrki stsrki added this to Support Aug 3, 2024
@stsrki stsrki moved this to ✔ Done in Support Aug 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status : Finished Finished work on issue, to be closed (merge/review pending, etc...) Type: Bug 🐞 Something isn't working
Projects
Archived in project
Development

No branches or pull requests

5 participants