A text input with a list of suggestions under it. The person types, the list narrows (or the
server searches) and choosing a suggestion sets the field. Behaviour lives in the
LedgerUI.Autocomplete hook (priv/static/ledger_ui/hooks/autocomplete.js).
<.autocomplete field={@form[:customer_id]} label="Customer" options={@customers}
on_search="search_customers" placeholder="Pick a customer" clearable />
<.autocomplete field={@form[:city]} options={["Salvador", "Santos"]} free_text />The choice is submitted through a hidden input named like the field; the visible input only
shows the label. A bubbling input event fires from the hidden input, so a surrounding
phx-change runs. With free_text the typed text is the value.
Without on_search the list filters itself on the client (ignoring case and accents). With it
the hook pushes %{"id" => id, "query" => text} (after debounce ms and search_threshold
characters) to target or the LiveView, shows loading_text until the reply and the server
answers by re-rendering options. Options may carry :hint (a dimmed note at the right),
:icon, :initials (an avatar, :tone "t1".."t5" picks its color, else taken from the label) and :disabled.
Summary
Functions
Attributes
id(:string) - Defaults tonil.name(:string) - Defaults tonil.value(:any) - Defaults tonil.field(Phoenix.HTML.FormField) - Defaults tonil.label(:string) - Defaults tonil.help(:string) - Defaults tonil.errors(:list) - Defaults to[].options(:list) - Defaults to[].placeholder(:string) - Defaults tonil.disabled(:boolean) - Defaults tofalse.display_value(:string) - Defaults tonil.free_text(:boolean) - Defaults tofalse.on_search(:string) - Defaults tonil.debounce(:integer) - Defaults to300.search_threshold(:integer) - Defaults to0.target(:any) - Defaults tonil.open_on_focus(:boolean) - Defaults tofalse.clearable(:boolean) - Defaults tofalse.clear_label(:string) - Defaults to"Clear".no_results(:string) - Defaults to"No results found".loading_text(:string) - Defaults to"Searching…".create(:string) - Defaults tonil.on_create(:any) - Defaults tonil.size(:string) - Defaults to"md". Must be one of"sm","md", or"lg".open(:boolean) - Renders the list open (static previews). Defaults tofalse.class(:any) - Defaults tonil.- Global attributes are accepted. Supports all globals plus:
["autofocus", "form", "required"].
Slots
optionprefix