Form
Form — HTML form rendering helpers and ~H template components.
Provides low-level tag builders (form_tag, input_tag, etc.) and higher-level component functions (Input.render, Select.render, etc.) for use from .march.html templates via the <.Form.Input /> syntax.
Component calling convention (self-closing): <.Form.Input name="email" type_="email" label="Email" gate={gate} /> desugars to: Form.Input.render(name: "email", type_: "email", label: "Email", gate: gate)
Wrapper component (with inner content): <.Form.Wrapper conn={conn} action="/login" method="post"> <.Form.Input name="email" type_="email" label="Email" gate={gate} /> <button type="submit">Log in</button> </.Form.Wrapper> desugars to (via lower.march): Form.Wrapper.render(conn: conn, action: "/login", method: "post", render_inner: fn -> ~H"""...""" end)
All component render functions return IOList so they compose inside ~H.
Functions
Render an error <span> for a field, or empty string if no error.
Form.error_tag(Depot.Gate.error_for(gate, "email"))Render a complete form field: label + input wrapper + error.
`name` is used as the label's `for` and the input's `id`.
`label_text` is the display label (empty → no label element rendered).
`input_html` is the pre-rendered input element.
`error` is the optional error message.
Form.field_tag("email", "Email", input_html, Depot.Gate.error_for(gate, "email"))Render a complete <form> tag with CSRF token and inner content.
The ~H desugarer already auto-injects the CSRF token into plain
<form method="post"> tags, so this is only needed when building
forms outside ~H templates.
Form.form_tag(conn, "/register", "post", "", content)Render an <input> element.
Form.input_tag("email", "email", "[email protected]", [("class", "input")])Render a <select> element with <option> elements.
`options` is a list of (label, value) pairs.
`selected` is the currently selected value (or empty string for none).
Form.select_tag("role", [("Admin", "admin"), ("Member", "member")], "admin", [])Render a <textarea> element.
Form.textarea_tag("body", "Hello world", [])