Skip to main content
widgets

CompletionEntry

Text entry with completion

by Patrice Ferlet

About

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()
}
addon screenshot

Installation

You can install this add-on using go get:

go get fyne.io/x/fyne/widget

Or you can download the code directly from git:

git clone https://github.com/fyne-io/fyne-x.git