Form Integration Components for Phoenix LiveView.
Provides components that integrate with Phoenix.HTML.Form and Ecto changesets.
Handles error display, real-time validation via phx-debounce, and form accessibility.
Components
| Function | Purpose |
|---|---|
phia_input/1 | All-in-one input: label + input + description + errors |
form_field/1 | Composable wrapper: label + slot + description + errors |
form_label/1 | Accessible <label> linked to input via field.id |
form_message/1 | Conditional error messages from changeset |
Error Translation
By default, errors are translated using a simple placeholder interpolator.
To use a custom translator (e.g., from gettext), configure:
config :phia_ui, :error_translator_function, {MyApp.CoreComponents, :translate_error}The custom function must accept {message, opts} and return a string.
Example
<.phia_input field={@form[:email]} type="email" label="Email" />
<.phia_input
field={@form[:password]}
type="password"
label="Password"
description="At least 8 characters."
/>
Summary
Functions
Composable form field wrapper.
Renders an accessible <label> linked to the input via for={@field.id}.
Renders changeset error messages for a field. Renders nothing when there are no errors.
Renders a form input integrated with Phoenix.HTML.FormField.
Translates a {message, opts} error tuple from a changeset.
Functions
Composable form field wrapper.
Renders: label → slot (input) → description → error messages. Use this when you need full control over the input element inside.
Attributes
field(Phoenix.HTML.FormField) (required) - APhoenix.HTML.FormFieldfrom@form[:field_name].label(:string) - Label text. Defaults tonil.description(:string) - Helper text below the input slot. Defaults tonil.
Slots
inner_block(required) - The input component (e.g. a native input or phia_input).
Renders an accessible <label> linked to the input via for={@field.id}.
Attributes
field(Phoenix.HTML.FormField) (required) - FormField to link the label to.class(:string) - Additional CSS classes. Defaults tonil.- Global attributes are accepted. HTML attributes forwarded to the label element.
Slots
inner_block(required) - Label text or content.
Renders changeset error messages for a field. Renders nothing when there are no errors.
Attributes
field(Phoenix.HTML.FormField) (required) - FormField to read errors from.class(:string) - Additional CSS classes. Defaults tonil.
Renders a form input integrated with Phoenix.HTML.FormField.
Includes label, input, description, and changeset error messages in a single component.
Applies phx-debounce="blur" by default for real-time validation.
Attributes
field(Phoenix.HTML.FormField) (required) - APhoenix.HTML.FormFieldfrom@form[:field_name].type(:string) - HTML input type. Defaults to"text".label(:string) - Label text rendered above the input. Defaults tonil.description(:string) - Helper text rendered below the input. Defaults tonil.class(:string) - Additional CSS classes for the input element. Defaults tonil.- Global attributes are accepted. HTML attributes forwarded to the input element. Supports all globals plus:
["autocomplete", "placeholder", "readonly", "required", "disabled"].
Translates a {message, opts} error tuple from a changeset.
Uses the configured :error_translator_function when set, otherwise falls back
to interpolating %{key} placeholders with values from opts:
Enum.reduce(opts, msg, fn {k, v}, acc -> String.replace(acc, "%{#{k}}", to_string(v)) end)Configure a custom translator:
config :phia_ui, :error_translator_function, {MyApp.CoreComponents, :translate_error}