Lavash.Form (Lavash v0.4.0-rc.3)

Copy Markdown View Source

A wrapper around Ash.Changeset that provides both form rendering and submission.

When a derived field returns an Ash.Changeset, Lavash automatically wraps it in this struct. This allows:

  • Rendering via Phoenix.HTML.FormData protocol (implemented by AshPhoenix.Form)
  • Submission via Ash.create/update/destroy

The wrapper is transparent to templates — it implements the Access behaviour (delegating form[:field] to the inner Phoenix.HTML.Form) and the Phoenix.HTML.FormData protocol (so <.form for={@my_form}> works directly).

Summary

Functions

Creates a form for an Ash resource.

Submits the form by running the underlying Ash action. Returns {:ok, result} or {:error, changeset}.

Wraps an Ash.Changeset, creating both the form for rendering and preserving the changeset for submission.

Functions

for_resource(resource, record, params, opts \\ [])

Creates a form for an Ash resource.

If record is nil or has no id, creates a form for the create action. Otherwise creates a form for the update action.

Options:

  • :create - the create action name (default: :create)
  • :update - the update action name (default: :update)
  • :as - the form name for params namespacing (default: "form")

submit(form, opts \\ [])

Submits the form by running the underlying Ash action. Returns {:ok, result} or {:error, changeset}.

Options:

  • :actor - The actor to use for authorization

wrap(changeset, form_name \\ "form")

Wraps an Ash.Changeset, creating both the form for rendering and preserving the changeset for submission.