{
"files": [
{
"content": "defmodule Shadix.Form do\n @moduledoc \"\"\"\n Form-integration helpers shared by Shadix form controls.\n\n `field_attrs/1` normalizes a `Phoenix.HTML.FormField` into plain attrs the\n controls render from. Isolating normalization here keeps the controls simple and\n makes a future low-level (`name`/`value`) escape hatch a one-place, additive change.\n \"\"\"\n\n @doc \"Normalizes a `Phoenix.HTML.FormField` into `%{id, name, value, errors}` (errors translated to strings).\"\n def field_attrs(%Phoenix.HTML.FormField{} = field) do\n %{\n id: field.id,\n name: field.name,\n value: field.value,\n errors: Enum.map(field.errors, &translate_error/1)\n }\n end\n\n @doc \"\"\"\n Translates a changeset error `{msg, opts}` into a string, interpolating `%{key}`\n placeholders. Non-gettext fallback (a component library cannot assume the host's\n gettext backend).\n \"\"\"\n def translate_error({msg, opts}) do\n Enum.reduce(opts, msg, fn {key, value}, acc ->\n String.replace(acc, \"%{#{key}}\", fn _ -> to_string(value) end)\n end)\n end\nend\n",
"path": "form.ex"
}
],
"hooks": [],
"name": "form",
"npm_deps": [],
"registry_deps": []
}