PhiaUi.Components.FormField (phia_ui v0.1.17)

Copy Markdown View Source

Composable form field wrapper for Phoenix LiveView.

form_field/1 provides a consistent layout shell — label, slot, optional description, and inline error messages — around any arbitrary input element passed via its inner_block slot. Use it when you need to compose your own input controls (e.g. custom selects, radio groups) while keeping the same visual structure as PhiaUi.Components.PhiaInput.

Usage

<.form_field field={@form[:email]} label="Email">
  <input id={@form[:email].id} name={@form[:email].name} type="email" />
</.form_field>

<.form_field
  field={@form[:role]}
  label="Role"
  description="Select the user's access level"
>
  <.phia_select field={@form[:role]} options={@roles} />
</.form_field>

Error display

Errors are sourced from field.errors and translated via the built-in placeholder interpolator, or the configured {Module, :function} set in:

config :phia_ui, :error_translator_function, {MyApp.CoreComponents, :translate_error}

Summary

Functions

form_field(assigns)

Attributes

  • field (Phoenix.HTML.FormField) (required)
  • label (:string) - Defaults to nil.
  • description (:string) - Defaults to nil.
  • class (:string) - Defaults to nil.

Slots

  • inner_block (required)