LiveReactNative.FormSerializer (live_react_native v0.0.3)

View Source

Serializes any Phoenix.HTML.FormData assign (Ecto changeset via to_form/1, AshPhoenix.Form, or a bare %Phoenix.HTML.Form{}) to a wire-safe shape the mobile client renders: %{name, params, errors, valid}.

The wire key is valid (JSON-friendly for the JS client), not the Elixir-idiomatic valid?. valid is nil until the form has an action set (i.e. has been validated); after that it reflects whether there are errors. Correctness still lives in the app's submit handler, which always re-validates server-side.

Summary

Functions

True only for FormData structs (never plain maps, which implement FormData for params-forms).

Serialize a single form value to the wire shape.

Map every form assign to its serialized shape; leave non-form assigns untouched.

Types

serialized()

@type serialized() :: %{
  name: String.t() | nil,
  params: map(),
  errors: %{required(String.t()) => [String.t()]},
  valid: boolean() | nil
}

Functions

form?(value)

@spec form?(term()) :: boolean()

True only for FormData structs (never plain maps, which implement FormData for params-forms).

serialize(value)

@spec serialize(term()) :: serialized()

Serialize a single form value to the wire shape.

serialize_assigns(assigns)

@spec serialize_assigns(map()) :: map()

Map every form assign to its serialized shape; leave non-form assigns untouched.