Peri.Form (peri v0.10.0)

Copy Markdown View Source

A form-ready struct holding Peri validation results.

Peri.Phoenix.to_form/3 builds this struct from a schema and raw params, and the Phoenix.HTML.FormData implementation (available when phoenix_html is loaded) converts it into a Phoenix.HTML.Form, so Peri schemas plug into Phoenix.Component.form/1 and <.input> without Ecto.

Fields

  • :schema - the Peri schema the params were validated against
  • :data - the validated data (atom keys), %{} when validation failed
  • :params - the raw params as received (usually string keys)
  • :errors - errors in changeset format, %{field => [{message, opts}]} with nested humanized maps under assoc keys (list entries keyed by index)
  • :name - the form name, defaults to "peri"
  • :action - the form action (:validate, :save, ...), used by LiveView to decide when to show errors

Summary

Types

errors()

@type errors() :: %{optional(atom()) => [{String.t(), keyword()}] | errors()}

t()

@type t() :: %Peri.Form{
  action: atom() | nil,
  data: map(),
  errors: errors(),
  name: String.t() | nil,
  params: map(),
  schema: Peri.schema() | nil
}