Form Wizard

A long form in steps: each step checks its own fields, optional steps can be skipped, a review at the end, and progress kept across reloads.

Workspace

Where your team's projects and docs will live.

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/form-wizard

Usage

import type { Step } from "./ui/uicontext/components/Stepper.ts"import { FormWizard, nextStep, type WizardState } from "./ui/uicontext/components/forms/Wizard.ts"
const steps: ReadonlyArray<Step> = [	{ id: "workspace", title: "Workspace" },	{ id: "invite", title: "Invite teammates", optional: true },	{ id: "review", title: "Review" },]// in update, on the form's submit: touch the step's fields, and move on once they pass//   const form = Signup.touch(model.form, ["workspace"])//   Signup.validate(form).passes(["workspace"]) ? { form, wizard: nextStep(steps, model.wizard) } : { form }export const advance = (wizard: WizardState) => nextStep(steps, wizard)export const Setup = <M, C extends View.Children<M>>(h: Html.H<M>, wizard: WizardState, body: C, on: { readonly submit: M; readonly back: M; readonly skip: M; readonly step: (id: string) => M }) =>	FormWizard(h, { id: "setup", steps, at: wizard, onSubmit: on.submit, onBack: on.back, onSkip: on.skip, onStep: on.step, children: body })

API reference

Options

FormWizard options
NameTypeDefaultDescription
idrequiredstring—The wizard's id: its heading and form ids start with it
stepsrequiredStep[]——
atrequiredWizardState——
leadstring—A sentence under the step's title
childrenrequiredView.Children—The current step's fields
onSteprequired(id: string) => Message—Go back to a step already done
onSubmitrequiredMessage—Next and the last step's submit: the form's own submit, so Enter in a field does it too
onBackrequiredMessage——
onSkipMessage—Shows Skip on an optional step
nextLabelstring"Continue""Continue" by default
busyboolean—A submit is in flight: Next waits
savedstring—Where saved progress stands: "Progress saved"
errorsstring[]—Steps with an error to fix, as the Stepper marks them
styleStyle——

Source