View Source PyroComponents.Components.Autocomplete (PyroComponents v0.1.1)

A flexible autocomplete component for Phoenix forms.

Overridable Component Attributes

You can customize the components in this module by configuring overrides.

The components in this module support the following overridable attributes:

  • render/1
    • :throttle_time :integer (required)
    • :option_label_key :atom (required)
    • :option_value_key :atom (required)
    • :prompt :string (required)
    • :class :css_classes
    • :input_class :css_classes
    • :listbox_class :css_classes
    • :listbox_option_class :css_classes
    • :description_class :css_classes

Summary

Components

A simple autocomplete component.

Components

A simple autocomplete component.

Examples

<.simple_form for={@form} phx-change="validate" phx-submit="save">
  <.live_component
    module={PyroComponents.Components.Autocomplete}
    id="fiend_id_autocomplete"
    field={@form[:friend_id]}
    label="Friend"
    search_fn={search_friends/1}
    lookup_fn={lookup_friend/1} />
  <:actions>
    <.button>Save</.button>
  </:actions>
</.simple_form>

Attributes

  • overrides (:list) - Manually set the overrides for this component (instead of config/default). Defaults to nil.
  • throttle_time (:integer) - (overridable, required).
  • option_label_key (:atom) - (overridable, required).
  • option_value_key (:atom) - (overridable, required).
  • prompt (:string) - the prompt for search input (overridable, required).
  • description (:string) - Defaults to nil.
  • errors (:list) - Defaults to [].
  • label (:string) - Defaults to nil.
  • input_id (:any) - Defaults to nil.
  • multiple (:boolean) - the multiple flag for select inputs. Defaults to false.
  • required (:boolean) - Defaults to false.
  • name (:any)
  • value (:any)
  • search_fn (:any) (required) - the arity-1 function to get options from search term.
  • lookup_fn (:any) (required) - the arity-1 function to get lookup/convert value to option.
  • no_results_message (:string) - the message to display if there are no results for the search phrase. Defaults to "[no results]".
  • field (Phoenix.HTML.FormField) - a form field struct retrieved from the form, for example: @form[:email].
  • autofocus (:boolean) - enable autofocus hook to reliably focus input on mount. Defaults to false.
  • class (:any) - (overridable, :css_classes).
  • input_class (:any) - class of the input element (overridable, :css_classes).
  • listbox_class (:any) - class of the listbox element (overridable, :css_classes).
  • listbox_option_class (:any) - class of the listbox option element (overridable, :css_classes).
  • description_class (:any) - class of the field description (overridable, :css_classes).

Slots

  • option_template