Arc.LiveView.Form (cratis_arc v0.1.0)

Copy Markdown View Source

A command as a Phoenix form.

Arc.LiveView.Form implements Phoenix.HTML.FormData, so Phoenix.Component.to_form/2, <.form> and the generated <.input> core component work with a command directly. Errors from the Arc pipeline appear on the matching field, using the member names of the validation results.

Form values arrive as strings. Empty strings become nil for fields that are not strings, and keys are snake_case field names, which Arc converts to the wire names it binds from.

You normally use it through Arc.LiveView.assign_form/4, validate_form/3 and submit_form/3.

Summary

Functions

A new, empty form for command, optionally prefilled with params.

Converts form params to the wire map the pipeline binds: snake_case keys become camelCase, and blank values of non-string fields become nil.

Types

t()

@type t() :: %Arc.LiveView.Form{
  action: atom() | nil,
  command: module(),
  errors: [{atom(), {String.t(), keyword()}}],
  params: map()
}

Functions

new(command, params \\ %{})

@spec new(module(), map()) :: t()

A new, empty form for command, optionally prefilled with params.

wire(command, params)

@spec wire(module(), map()) :: map()

Converts form params to the wire map the pipeline binds: snake_case keys become camelCase, and blank values of non-string fields become nil.