How to revert the default chip selected?
Closed this issue · 8 comments
I set the initialValue: ["ABC", "DEF"], when I choose the other one is "XYZ". For now, the selected item is adding "XYZ" : ["ABC", "DEF", "XYZ"] right?
If I don't wanna "XYZ" anymore and for instance, I press the "Cancel" button to revert the selected item like initialValue: ["ABC", "DEF"].
What am I supposed to solve this? Do you have any idea or solution for this case?
Thank you! Nice day!
Sorry I don't quite understand.
The initialValue should be a single value, e.g "ABC".
Well, the initialValue is the initial value shown in the Textfield right?
So I type to search and add some items, so data in the onChange
show me the List combining the initialValue and some things added.
But I don't want some new items anymore, I'd like the Textfield to show the initialValue.
Let's look at the image attached below:
For instance, the initialValue is Afghanistan and I'll add Albania later. But I'd decide to remove Albania. Suppose I have a button, then press this button, the TextField will remove the change item Albania and show the Afghanistan like the beginning.
If you want to modify the suggestions, you'll have to modify findSuggestions
.
Nope, I think it's about onChange
and initialValue
because when I add some new items by searching from findSuggestions
and I want to reset the TextField like the beginning before I choose the new ones. You get what I am saying, right?
Ah okay, I think I get it now. I guess you'd like to change the state from outside the stateful widget.
If you simply want to reset the state, I think the easiest way is to create the widget with a new key:
https://stackoverflow.com/questions/62332971/flutter-reset-statefulwidget-state-when-widget-is-recreated
Oh, It does help my case. To reset the state means clearing all items in the TextField
and adding initialValue
again.
I am finding things like the reset()
function from the Key
of ChipsInputState
but it doesn't exist. The reset function looks like from the link below.
https://stackoverflow.com/questions/69134642/flutter-how-to-reset-automatically-a-dropdown-search-field-after-form-submition
Oh thank god and thank you! I have already fixed that!
okay cool!