Skip to content

AutoComplete

Helps the user make a selection by entering some text and choosing from among a list of displayed options.

Inherits: Control

Properties

Events

Examples#

Live example

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)

basic

Properties#

selected_index #

selected_index

suggestions #

suggestions: list[AutoCompleteSuggestion] = field(
    default_factory=list
)

A list of AutoCompleteSuggestion controls representing the suggestions to be displayed.

Note
  • A valid AutoCompleteSuggestion must have at least a key or value specified, else it will be ignored. If only key is provided, value will be set to key as 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.