The CompletionEntry is a text entry with a List that is completed when OnChanged
is triggered.
Code
entry := widget.NewCompletionEntry([]string{})
// When the use typed text, complete the list.
entry.OnChanged = func(s string) {
// completion start for text length >= 3
if len(s) < 3 {
entry.HideCompletion()
return
}
// Make a search on wikipedia
resp, err := http.Get(
"https://en.wikipedia.org/w/api.php?action=opensearch&search=" + entry.Text,
)
if err != nil {
entry.HideCompletion()
return
}
// Get the list of possible completion
var results [][]string
json.NewDecoder(resp.Body).Decode(&results)
// no results
if len(results) == 0 {
entry.HideCompletion()
return
}
// then show them
entry.SetOptions(results[1])
entry.ShowCompletion()
}
Usage
You can use this directly from the source code using standard go imports:
go get fyne.io/x/fyne/widget@latest
Or you can download the code directly from git:
git clone https://github.com/fyne-io/fyne-x.git
Screenshots
The component is demonstrated in the following images: