Megabit / Blazorise

Blazorise is a component library built on top of Blazor with support for CSS frameworks like Bootstrap, Tailwind, Bulma, AntDesign, and Material.
https://blazorise.com/
Other
3.31k stars 533 forks source link

How to reset/empty the selectedValue of Autocomplete? #142

Closed howardgod closed 5 years ago

howardgod commented 5 years ago

I tried following code, but the selectedValue still there. I also try with SelectedValue and SelectValueChange way, still fail. Any tips to accomplish this?

<div class="row">
    <Field Class="col-6">
        <Autocomplete Data="@users" @bind-SelectedValue="@selectedReviewer"
                      TextField="@((item)=>item)"
                      ValueField="@((item)=>item)"
                      Placeholder="Search..."></Autocomplete>
    </Field>
    <SimpleButton Color="Color.Success" Clicked="@OnAddReviewer">
        <span class="oi oi-plus" aria-hidden="true"></span>
    </SimpleButton>
</div>

@code {
    object selectedReviewer;
    void OnAddReviewer()
    {
        Reviewers.Add(selectedReviewer.ToString());
        selectedReviewer = null ;
        StateHasChanged();
    }
}
stsrki commented 5 years ago

Could be a bug in Autocomplete. Can you first try to change the TextField and ValueVield to something like this:

TextField="@((item)=>item.Name)"
ValueField="@((item)=>item.UserId)"
howardgod commented 5 years ago

The "@user is List<string>". So there's no Name or UserId fields. Does Data field only accept those complex type like following?

class User
{
public string Name {get;set;}
public string Id {get;set;}
}
stsrki commented 5 years ago

I only assumed it was a complex object since that was the intended was of using the autocomplete. But I think it should still work with regular List<string>.

I will look more into this but keep in mind that I'm still actively working on version 0.8 of Blazorise. It is going to be pretty big upgrade so it will take a while until I release it.

howardgod commented 5 years ago

I change to complex type, can't work still. thanks for your time. no rush. :)

howardgod commented 5 years ago

After checking the source code, I feel like the problem is the <Text Edit Text="@SelectedText"/> under <Dropdown> component. The SelectedValue is not the same property as SelectedText. So when user changes SelectedValue, it won't affect the SelectedText

camping89 commented 3 years ago

Any update on how to clear the Autocomplete component?

stsrki commented 3 years ago

@camping89 Setting the SelectedValue should work. Can you create a new ticket with the code to reproduce it issue on our side?

rgomezia commented 2 years ago

@howardgod hey man , you can do this....i have the same problem on 1.0.1 , i need clean the autocomplete value / text on edit template for grid , but its imposible

David-Moreira commented 2 years ago

@stsrki comment should work, this is an old issue, I'll be opening a new one to investigate this.

ninjanerdbgm commented 2 years ago

@howardgod hey man , you can do this....i have the same problem on 1.0.1 , i need clean the autocomplete value / text on edit template for grid , but its imposible

Add this to your Autocomplete component:

@bind-SelectedText="@selectedReviewer"