Wizard

Wizard forms CompositeController

Multi-stage form navigation: the stepper drives stage reveal — back freely, forward one validated step at a time.

Layer: L2 host · Recipe: unset — see docs/agent/pick-a-surface.md. Curriculum: AGENTS.md; pick matrix: docs/agent/pick-a-surface.md; blast radius: CONSUMER_MAP.md.

Copy this

html
<div data-wizard data-step="0" class="hm-measure-lg">
  <ol class="form-stepper" role="list" aria-label="Form progress">
    <li class="form-stepper-item is-not-last" data-state="current" aria-current="step"><button type="button" class="form-stepper-button" data-step-to="0"><span class="form-stepper-circle is-active"><span>1</span></span><span class="form-stepper-label is-active">Details</span><span class="visually-hidden" data-step-status>current</span></button><span class="form-stepper-connector" aria-hidden="true"></span></li>
    <li class="form-stepper-item is-not-last" data-state="pending"><button type="button" class="form-stepper-button" data-step-to="1"><span class="form-stepper-circle"><span>2</span></span><span class="form-stepper-label">Schedule</span><span class="visually-hidden" data-step-status>pending</span></button><span class="form-stepper-connector" aria-hidden="true"></span></li>
    <li class="form-stepper-item" data-state="pending"><button type="button" class="form-stepper-button" data-step-to="2"><span class="form-stepper-circle"><span>3</span></span><span class="form-stepper-label">Review</span><span class="visually-hidden" data-step-status>pending</span></button></li>
  </ol>
  <div class="wizard-stage" data-stage="0">
    <div class="form-field">
      <label class="form-label" for="hm-wiz-name">Project name<span class="form-required" aria-hidden="true">*</span></label>
      <input id="hm-wiz-name" class="form-input" type="text" required aria-required="true">
    </div>
  </div>
  <div class="wizard-stage" data-stage="1" hidden>
    <div class="form-field">
      <label class="form-label" for="hm-wiz-date">Start date</label>
      <input id="hm-wiz-date" class="form-input" type="date">
    </div>
  </div>
  <div class="wizard-stage" data-stage="2" hidden>
    <p>Review your answers, then submit.</p>
  </div>
</div>

Server exchange

This Hyperpart has no server exchange — it is presentation or client chrome only. htmx does not issue a request on this part's behalf. If you put an affordance (hx-*) on a control that uses this markup, that action's exchange belongs to the action, not this part. See Swap contract for host-owned envelopes.

Swap contract

Agent-visible HTMX topology (ADR-0054 / decision 0012). exchange envelope = what the response may re-emit relative to the persistent slot (body_only | outer | none | host_owned | document). dual-lock validates part markup only — not this envelope. Stem: stems/morph-safe-hypermedia.md; decision: docs/decisions/0012-swap-identity-contract.md.

No host HTMX exchange on this part — presentation or client chrome only. exchange envelope: n/a.

If a host wraps this markup in hx-*, that host owns the swap contract (sole identity + envelope). Prefer innerMorph / outerMorph for stable slots; replacement for flash; body-only responses under inner swaps.

Envelope response examples

This part has no owned exchange (envelope n/a). If a host adds hx-*, that host’s envelope applies — typically body_only:

html
<!-- Host wraps this presentation part with hx-* (host owns envelope) -->
<!-- Prefer: hx-swap="innerMorph" hx-target="#panel-body" -->
<!-- Server returns body_only interior for #panel-body -->
<div class="dz-stack">content…</div>

Do not re-own the slot:

html
<!-- WRONG: server returns the presentation root with a new id every poll -->
<div id="wizard-root" data-dz-region>…</div>

How to use it

Seams

  • root data-step is the current stage; stages use native hidden
  • stepper items carry data-state=complete|current|pending (CSS checkmark)

Do / Don't

DoDon't
keep stage index in data-step on the wizard rootstore step in a JS variable a morph would discard

Pitfalls

  • forward only after reportValidity() on the current stage's required inputs
  • no-JS still posts the whole form — stage one is the visible path

Keyboard / AT

  • Back is always free; Forward is one step and validity-gated
  • invalid inputs receive focus so the browser validity bubble appears

Related parts

field button progress

DOM contract

What the emitted HTML must satisfy — the table is the required surface; Python under contracts/ is the package-internal dual-lock CI runs (tests/test_contracts.py), not an app route. Standalone HTMX4: implement the API so responses match this markup. Dazzle: the agent emits SSR that already satisfies it. Do not invent attrs outside these tables. For request/response wiring see Server exchange.

contracts/wizard.py

Required in the DOM: root [data-wizard] (part wizard). Emit only these attributes — inventing extras is fine only if controllers ignore them; omitting required ones fails CI (tests/test_contracts.py).

NodeAttrConstraint
[data-wizard]data-steppresent (any value)
[data-stage]data-stagepresent (any value)
[data-state]data-stateone of ['complete', 'current', 'pending']

Module source

Import path is monorepo/package-local (from contracts._kit import …). Source-token form often uses data-*; gallery demos above are unprefixed. Do not copy this into app routes.

python
"""HYPERPART: wizard — multi-stage form with data-dz-step state."""

from contracts._kit import DomContract, Node, OneOf, Present

DOM_CONTRACT = DomContract(
    part="wizard",
    root="[data-dz-wizard]",
    nodes=(
        Node("[data-dz-wizard]", attrs={"data-dz-step": Present()}),
        Node("[data-dz-stage]", attrs={"data-dz-stage": Present()}),
        Node(
            "[data-dz-state]",
            attrs={"data-dz-state": OneOf("complete", "current", "pending")},
        ),
    ),
)

__all__ = ["DOM_CONTRACT"]

Notes

State-in-DOM: the root's data-step is the current stage; stages toggle via the native hidden attribute; stepper items carry data-state="complete|current|pending" (the checkmark is pure CSS off the state). wizard.js allows going BACK freely and FORWARD one step at a time — only after every required input in the current stage passes reportValidity(). No-JS renders stage one with numbered steps (the form still posts whole).

Source files

One logical Hyperpart, 4 code items (CSS layered, JS bundled). Bound by HYPERPART: wizard — python tools/hyperpart.py wizard lists them.

site/registry.py · contracts/wizard.py · components/form-chrome.css:143 · controllers/dz-wizard.js

Composed of

Form chrome · Field