{#- chirp-ui: Form field macros Extended field macros with BEM styling. These complement (and can replace) Chirp's built-in form macros from "chirp/forms". Internal: field_wrapper provides label, hint, error display. Standard fields use it; checkbox/toggle/radio/range/input_group have custom layouts. -#} {% def form(action, method="get", enctype=none, cls="", attrs="", attrs_map=none, hx_get=none, hx_post=none, hx_put=none, hx_patch=none, hx_delete=none, hx_target=none, hx_swap=none, hx_trigger=none, hx_include=none, hx_select=none, hx_select_oob=none, hx_disabled_elt=none, hx_sync=none, hx_ext=none, hx_vals=none, hx_reset_on_success=none) %} {#- hx_reset_on_success: when true, form resets after successful htmx response (2xx). Defaults to true when form has hx-post/put/patch/delete (via params or attrs_map). See https://htmx.org/examples/reset-user-input/ hx_sync: pass explicitly or via attrs_map to prevent double-submit; e.g. "this:replace". See https://htmx.org/docs/#synchronization -#} {% set _has_hx = hx_post or hx_put or hx_patch or hx_delete or (attrs_map or {}).get("hx-post") or (attrs_map or {}).get("hx-put") or (attrs_map or {}).get("hx-patch") or (attrs_map or {}).get("hx-delete") %} {% set _reset = hx_reset_on_success if hx_reset_on_success is not none else _has_hx %} {% set _sync_from_attrs = (attrs_map or {}).get("hx-sync") %} {% set _sync = hx_sync if hx_sync is not none else _sync_from_attrs %}
{% end %} {% def fieldset(legend=none, cls="") %} {% end %} {# Shared wrapper: label, slot (control), hint, errors. modifier adds chirpui-field--X. #} {% def field_wrapper(name, label=none, errors=none, required=false, hint=none, modifier="") %}