Wizard

One step of a multi-step form, with the progress, the fields and Back and Next buttons.

Updated

Default

  1. Account Your details
  2. Plan Pick a size
  3. Payment Card or invoice

You can change it later


{component wizard,
	action: '/join/plan',
	back: '/join/account',
	items: [
		['title' => 'Account', 'description' => 'Your details'],
		['title' => 'Plan', 'description' => 'Pick a size', 'active' => true],
		['title' => 'Payment', 'description' => 'Card or invoice'],
	],
}
	{ui field, name: 'plan', label: 'Plan', hint: 'You can change it later'}
		{ui select, name: 'plan', options: ['small' => 'Small', 'large' => 'Large'] /}
	{/ui}
{/component}

The server holds the answers and renders the step it is on, so the wizard is the frame of one step. items are the steps, as for {ui steps}, and the one marked active is the step shown. The tag's content holds the step's fields. back is the previous step's URL, and is left out on the first step. The form posts to action, and your router validates it, keeps the answers in the session and renders the next step.

The last step

  1. Account
  2. Plan
  3. Payment

{component wizard,
	action: '/join/payment',
	back: '/join/plan',
	submit: 'Pay now',
	items: [
		['title' => 'Account'],
		['title' => 'Plan'],
		['title' => 'Payment', 'active' => true],
	],
	attrs: ['hx-post' => '/join/payment', 'hx-target' => 'closest .wizard', 'hx-swap' => 'outerHTML'],
}
	{ui field, name: 'card', label: 'Card number'}
		{ui input, name: 'card', placeholder: '4242 4242 4242 4242' /}
	{/ui}
{/component}

When the active step is the last, the button reads submit instead of next. To swap the form in place rather than load a page, give attrs the hx-post, hx-target and hx-swap of any form.