AutoComplete
Examples#
Basic example#
import flet as ft
def main(page: ft.Page):
page.add(
ft.AutoComplete(
on_select=lambda e: print(e.control.selected_index, e.selection),
suggestions=[
ft.AutoCompleteSuggestion(key="one 1", value="One"),
ft.AutoCompleteSuggestion(key="two 2", value="Two"),
ft.AutoCompleteSuggestion(key="three 3", value="Three"),
],
),
ft.Text("Type in 1, 2 or 3 to receive suggestions."),
)
ft.run(main)
AutoComplete
#
Bases: Control
Helps the user make a selection by entering some text and choosing from among a list of displayed options.
on_select
#
on_select: EventHandler[AutoCompleteSelectEvent] | None = (
None
)
Called when a suggestion is selected.
suggestions
#
suggestions: list[AutoCompleteSuggestion] = field(
default_factory=list
)
A list of AutoCompleteSuggestion
controls representing the suggestions to be displayed.
Note
- A valid
AutoCompleteSuggestionmust have at least akeyorvaluespecified, else it will be ignored. If onlykeyis provided,valuewill be set tokeyas fallback and vice versa. - The internal filtration process of the suggestions (based on their
keys) with respect to the user's input is case-insensitive because the comparison is done in lowercase.
