Flicker.AshPhoenixForm (Flicker v0.1.0)

Copy Markdown View Source

An optional AshPhoenix.Form adapter for form-field mode (ADR-005).

This module only compiles when ash_phoenix is present — ash_phoenix is not a hard dependency of Flicker (ADR-006). Plain Phoenix forms and controlled mode don't need it at all.

A Flicker.select/1 in form-field mode owns its own hidden input, but applying a selection also needs to land in the host's %AshPhoenix.Form{} so the rest of the form (validation, other fields' _unused_ markers) doesn't get reset out from under it. attach/2 installs one handle_info hook per host form that does exactly that — merging the selected value into the form's existing raw params rather than replacing them (the hard-won part of ADR-005; ported from the origin implementation per the extraction notes).

Usage

def mount(_params, _session, socket) do
  {:ok, socket |> assign(form: to_form(...)) |> Flicker.AshPhoenixForm.attach(form: :form)}
end

Pass on_select: fn socket, form -> socket end to run further logic (e.g. loading a dependent field's options) after the form revalidates.

Summary

Functions

Attaches a :handle_info hook to socket that applies Flicker selections targeting the AshPhoenix.Form assigned at opts[:form].

Functions

attach(socket, opts)

Attaches a :handle_info hook to socket that applies Flicker selections targeting the AshPhoenix.Form assigned at opts[:form].

opts:

  • :form — required. The socket assign key holding the %AshPhoenix.Form{} (as passed to to_form/2).
  • :on_select — optional fun(socket, form) :: socket, run after the form revalidates.