SearchField suggestionModel

I noticed suggestionModel was not available for SearchField

What is the best way to have a dropdown like a ComboBox, but allow for new entries?

I’m not sure understand correctly, but I use SearchField
onTextChanged: listModel.update()

with something like:

      model:   ListModel {
                      id: listModel
                      function update() {
                        clear()
                        if (searchField.text != "") {
                            searchPage.search(searchField.text);
                        }
                      }
                    }

This will give you substring match filtering of the input list as you add characters.

6 Likes

Not sure if that will work, but in general, ContextMenu is nothing special, you may be able to cram a TextField into one (maybe abusing a MenuLabel and adding TextField as a child).

suggestionModel is what gives you like autocomplete functionality, i guess i’ll make a component with a textfield and a hidden listview below with limited amount of options and use that for the suggestions and then fill the textfield with the pressed item in the list below and hide the listview again. and then add an rightItem icon to open the listview regardless

But, what I suggested above does exactly that. That will limit the listings shown in a SilicaListView. This is from the DWD german weather client. I prefill the model with a lot of placen ames (and lat/long, etc). The searchfield let’s you limit via substring match with no more code than you see there.

4 Likes