AutoComplete
Helps the user make a selection by entering some text and choosing from among a list of suggestions.
Examples
Basic example
- Python
import flet as ft
def main(page: ft.Page):
page.add(
ft.AutoComplete(
suggestions=[
ft.AutoCompleteSuggestion(key="one 1", value="One"),
ft.AutoCompleteSuggestion(key="two 2", value="Two"),
ft.AutoCompleteSuggestion(key="three 3", value="Three"),
],
on_select=lambda e: print(e.control.selected_index, e.selection),
)
)
ft.app(main)
Properties
selected_index
The index of the selected suggestion in the list of suggestions
.
This property is read-only and None
at initialization, until a suggestion is selected for the first time.
Valule is of type int
.
suggestions
A list of AutoCompleteSuggestion
controls representing the suggestions to be displayed.
Note:
- The internal filtration process of the suggestions (based on their
key
s) with respect to the user's input is case-insensitive because the comparison is done in lowercase. - A valid
AutoCompleteSuggestion
must have at least akey
orvalue
specified, else it will be ignored. If onlykey
is provided,value
will be set tokey
as fallback and vice versa.
suggestions_max_height
The maximum - visual - height of the suggestions list.
Value is of type OptionalNumber
and defaults to 200
.
Events
on_select
Fires when a suggestion is selected.
Event handler is of type AutoCompleteSelectEvent
.