LedgerUI.Components.TagsInput (LedgerUI v0.2.0)

Copy Markdown View Source

A tag input: what is typed becomes a tag on Enter, Tab or a comma (pasting a comma separated list creates several); tags are removed with Backspace or their remove button. Behaviour lives in the LedgerUI.TagsInput hook (priv/static/ledger_ui/hooks/tags_input.js).

<.tags_input label="Tags" placeholder="Enter tags" field={@form[:tags]} removable />
<.tags_input name="tags" value={["awesome", "neat"]} removable restore_on_backspace />
<.tags_input name="tags" value="clear,items" clearable max={5} />

value is a list of strings or a comma separated string. The tags are submitted as name[] (plus an empty name[], so an empty list still reaches the server) through a hidden <select multiple>, and each change fires a bubbling input event for phx-change. suggestions (or options) are offered in the list while typing; with create={false} only listed options can be chosen and on_search pushes %{"id" => id, "query" => text} to target (or the LiveView), which answers by re-rendering options.

Summary

Functions

tags_input(assigns)

Attributes

  • id (:string) - Defaults to nil.
  • name (:string) - Defaults to nil.
  • value (:any) - Defaults to nil.
  • field (Phoenix.HTML.FormField) - Defaults to nil.
  • label (:string) - Defaults to nil.
  • help (:string) - Defaults to nil.
  • errors (:list) - Defaults to [].
  • placeholder (:string) - Defaults to nil.
  • suggestions (:list) - Defaults to [].
  • options (:list) - Defaults to nil.
  • selected_options (:list) - Defaults to [].
  • create (:boolean) - Defaults to true.
  • on_search (:string) - Defaults to nil.
  • debounce (:integer) - Defaults to 300.
  • removable (:boolean) - Defaults to false.
  • clearable (:boolean) - Defaults to false.
  • clear_label (:string) - Defaults to "Clear".
  • remove_label (:string) - Defaults to "Remove".
  • create_label (:string) - Defaults to "Add".
  • persist (:boolean) - Defaults to true.
  • restore_on_backspace (:boolean) - Defaults to false.
  • create_hint (:string) - Defaults to "Enter".
  • max (:integer) - Defaults to nil.
  • counter (:boolean) - Defaults to true.
  • limit_placeholder (:string) - Defaults to "Limit reached".
  • create_position (:string) - Defaults to "top". Must be one of "top", or "bottom".
  • compact (:boolean) - Defaults to false.
  • no_results (:string) - Defaults to "No results found".
  • disabled (:boolean) - Defaults to false.
  • target (:any) - Defaults to nil.
  • class (:any) - Defaults to nil.
  • Global attributes are accepted. Supports all globals plus: ["form"].

Slots

  • item
  • option