AutoComplete
Helps the user make a selection by entering some text and choosing from among a list of displayed options.
Inherits: Control
Properties
-
selected_index– -
suggestions(list[AutoCompleteSuggestion]) –A list of
AutoCompleteSuggestion -
suggestions_max_height(Number) –The maximum - visual - height of the suggestions list.
Events
-
on_select(EventHandler[AutoCompleteSelectEvent] | None) –Called when a suggestion is selected.
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)
Properties#
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.
suggestions_max_height
#
suggestions_max_height: Number = 200
The maximum - visual - height of the suggestions list.
Events#
on_select
#
on_select: EventHandler[AutoCompleteSelectEvent] | None = (
None
)
Called when a suggestion is selected.
