Search code examples
htmlvue.jsinputautocompleteautosuggest

Set AutoCompleteInput to suggest list of words


In my Vue project I found that setting the id to "autocompleteInput" made it suggest prevously typed words then the input field is focused:

                <input
                  id="autocompleteInput"
                />

But how do I make it suggest a list of words by default? E.g. how to give the autocompleteInput a list like this: ["Germany", "France", "Spain"] and then it suggests those?

I dont know why setting input id to "autocompleteInput" gives previously typed suggestions but it does.


Solution

  • Solved: Found this simple solution:

                  <input
                      list="browsers"
                    />
                    <datalist id="browsers">
                      <option value="Chrome"></option>
                      <option value="Firefox"></option>
                    </datalist>