FormWizard
FormWizard and WizardStep build a server-driven multi-step form flow. They are designed for HTMX partial replacement: your server decides the current step, then returns the wizard again.
Use Stepper when you only need progress display. Use FormWizard when the user is actively moving through form panels.
Import
Basic Usage
FormWizard(
WizardStep(
"Account",
Input("email", input_type="email", label="Email"),
),
WizardStep(
"Profile",
Input("company", label="Company"),
),
current_step=0,
endpoint="/setup",
hx_target="#setup-wizard",
id="setup-wizard",
)
Complete HTMX Flow
from fasthtml.common import fast_app
from faststrap import FormWizard, WizardStep, Input
app, rt = fast_app()
def setup_wizard(step: int = 0):
return FormWizard(
WizardStep("Account", Input("email", input_type="email", label="Email")),
WizardStep("Profile", Input("company", label="Company")),
WizardStep("Finish", Input("plan", label="Plan")),
current_step=step,
endpoint="/setup",
hx_target="#setup-wizard",
id="setup-wizard",
)
@rt("/")
def home():
return setup_wizard()
@rt("/setup", methods=["POST"])
async def setup(request):
form = await request.form()
step = int(form.get("step", 0))
return setup_wizard(step)
The wizard posts a step value when the user clicks Back, Next, or Finish. Your route can validate the current step before returning the next one.
Parameters
| Param | Type | Description |
|---|---|---|
*steps |
Any |
WizardStep panels. |
current_step |
int |
Zero-based active step index. |
endpoint |
str | None |
Form/HTMX endpoint. |
method |
get | post |
Submission method. |
step_name |
str |
Submitted field name for the next step index. |
next_label |
str |
Next button label. |
previous_label |
str |
Previous button label. |
finish_label |
str |
Final step button label. |
show_stepper |
bool |
Show a progress stepper above the current panel. |
hx_target |
str | None |
HTMX target for partial replacement. |
faststrap.components.forms.form_wizard.FormWizard(*steps, current_step=0, endpoint=None, method='post', step_name='step', next_label='Next', previous_label='Back', finish_label='Finish', show_stepper=True, hx_target=None, hx_swap='outerHTML', controls_cls=None, **kwargs)
Render a server-driven multi-step form shell.
Source code in src/faststrap/components/forms/form_wizard.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
faststrap.components.forms.form_wizard.WizardStep(title, *content, description=None, icon=None, **kwargs)
Render one FormWizard step panel.