PtahUi.Components.Form (PtahUI v0.1.0)

Copy Markdown View Source

Form input components: text input, select, and checkbox. All components integrate with Phoenix.HTML.Form and changeset errors.

Summary

Functions

Renders a checkbox with label and error support for use inside forms.

Renders a labelled text input.

Renders a labelled select dropdown.

Functions

checkbox_field(assigns)

Renders a checkbox with label and error support for use inside forms.

Examples

<.checkbox_field field={@form[:agree]} label="Concordo com os termos" />
<.checkbox_field name="newsletter" checked={@subscribed} label="Receber newsletter" />

Attributes

  • id (:any) - Defaults to nil.
  • name (:any) - Defaults to nil.
  • label (:string) (required)
  • checked (:boolean) - Defaults to false.
  • disabled (:boolean) - Defaults to false.
  • errors (:list) - Defaults to [].
  • field (Phoenix.HTML.FormField) - a form field struct.
  • Global attributes are accepted.

input(assigns)

Renders a labelled text input.

Examples

<.input field={@form[:email]} label="Email" type="email" required />
<.input name="search" value={@query} placeholder="Pesquisar..." />

Attributes

  • id (:any) - Defaults to nil.
  • name (:any) - Defaults to nil.
  • label (:string) - Defaults to nil.
  • value (:any) - Defaults to nil.
  • type (:string) - Defaults to "text".
  • placeholder (:string) - Defaults to nil.
  • required (:boolean) - Defaults to false.
  • disabled (:boolean) - Defaults to false.
  • hint (:string) - Defaults to nil.
  • errors (:list) - Defaults to [].
  • field (Phoenix.HTML.FormField) - a form field struct, e.g. @form[:email].
  • class (:string) - Defaults to nil.
  • Global attributes are accepted. Supports all globals plus: ["autocomplete", "maxlength", "minlength", "pattern", "readonly", "phx-debounce"].

select(assigns)

Renders a labelled select dropdown.

Examples

<.select field={@form[:role]} label="Função" options={[{"Admin", "admin"}, {"User", "user"}]} />
<.select name="country" label="País" options={@countries} prompt="Selecionar..." />

Attributes

  • id (:any) - Defaults to nil.
  • name (:any) - Defaults to nil.
  • label (:string) - Defaults to nil.
  • value (:any) - Defaults to nil.
  • options (:list) (required)
  • prompt (:string) - Defaults to nil.
  • required (:boolean) - Defaults to false.
  • disabled (:boolean) - Defaults to false.
  • errors (:list) - Defaults to [].
  • field (Phoenix.HTML.FormField) - a form field struct.
  • class (:string) - Defaults to nil.
  • Global attributes are accepted.