Form wizard
A wizard that splits a long form into steps; finished steps can be clicked to go back.
zb:stepper zubazar/ui-pro
This component is in Zubazar UI Pro; Zubazar UI Pro brings Zubazar UI with it. Installing Zubazar UI Pro →
Basic usage
steps is a key => title array; put each step's content in an zb:stepper.step with the same key and give the buttons data-stepper-next and data-stepper-previous.
<zb:stepper :steps="['project' => 'Project', 'team' => 'Team', 'confirm' => 'Confirmation']">
<zb:stepper.step name="project"><zb:input name="t_name" label="Project name" /></zb:stepper.step>
<zb:stepper.step name="team"><zb:input name="t_people" label="Number of people" type="number" /></zb:stepper.step>
<zb:stepper.step name="confirm"><zb:alert variant="success">The details are ready. Press Save to create the project.</zb:alert></zb:stepper.step>
<div class="mt-6 flex justify-between">
<zb:button variant="white" data-stepper-previous class="group-data-first/stepper:invisible">Back</zb:button>
<zb:button data-stepper-next class="group-data-last/stepper:hidden">Next</zb:button>
<zb:button variant="success" class="hidden group-data-last/stepper:inline-flex" x-on:click="$dispatch('toast', { type: 'success', message: 'Project saved.' })">Save</zb:button>
</div>
</zb:stepper>
| Prop | Values |
|---|---|
steps | key => title |
zb:stepper.step name | The key in steps |
data-stepper-next · data-stepper-previous | Goes to the next / previous step |
group-data-first/stepper · group-data-last/stepper | Classes for the first / last step |
Steps with descriptions
Give a step as a ['title' => …, 'description' => …] array; the description shows below the title.
<zb:stepper :steps="[
'project' => ['title' => 'Project', 'description' => 'Basic details'],
'team' => ['title' => 'Team', 'description' => 'Team members'],
'confirm' => ['title' => 'Confirmation', 'description' => 'Review and save'],
]">
<zb:stepper.step name="project"><zb:input name="a_name" label="Project name" /></zb:stepper.step>
<zb:stepper.step name="team"><zb:input name="a_people" label="Number of people" type="number" /></zb:stepper.step>
<zb:stepper.step name="confirm"><p class="text-sm text-dim">Review the details and save.</p></zb:stepper.step>
<div class="mt-6 flex justify-between">
<zb:button variant="white" data-stepper-previous class="group-data-first/stepper:invisible">Back</zb:button>
<zb:button data-stepper-next class="group-data-last/stepper:invisible">Next</zb:button>
</div>
</zb:stepper>
| Prop | Values |
|---|---|
title | Step title |
description | Short description below the title |
With icons
variant="icons" shows each step's icon instead of a number; finished steps keep the icon too.
<zb:stepper variant="icons" :steps="[
'account' => ['title' => 'Account', 'icon' => 'user'],
'security' => ['title' => 'Security', 'icon' => 'lock-closed'],
'notifications' => ['title' => 'Notifications', 'icon' => 'bell'],
]">
<zb:stepper.step name="account"><zb:input name="i_name" label="Full name" /></zb:stepper.step>
<zb:stepper.step name="security"><zb:input name="i_password" type="password" label="Password" viewable /></zb:stepper.step>
<zb:stepper.step name="notifications"><zb:switch name="i_sms" label="SMS notifications" checked /></zb:stepper.step>
<div class="mt-6 flex justify-between">
<zb:button variant="white" data-stepper-previous class="group-data-first/stepper:invisible">Back</zb:button>
<zb:button data-stepper-next class="group-data-last/stepper:invisible">Next</zb:button>
</div>
</zb:stepper>
| Prop | Values |
|---|---|
variant | numbered | icons |
icon | zb:icon name |
Starting step
current picks the step the wizard opens on, and the steps before it count as finished.
<zb:stepper current="team" :steps="['project' => 'Project', 'team' => 'Team', 'confirm' => 'Confirmation']">
<zb:stepper.step name="project"><zb:input name="b_name" label="Project name" value="Mobile app" /></zb:stepper.step>
<zb:stepper.step name="team"><zb:input name="b_people" label="Number of people" type="number" /></zb:stepper.step>
<zb:stepper.step name="confirm"><p class="text-sm text-dim">Review the details and save.</p></zb:stepper.step>
<div class="mt-6 flex items-center justify-between">
<zb:button variant="white" data-stepper-previous class="group-data-first/stepper:invisible">Back</zb:button>
<zb:button data-stepper-next class="group-data-last/stepper:invisible">Next</zb:button>
</div>
</zb:stepper>
| Prop | Values |
|---|---|
current | Key of the step shown on open |
data-step | The current step's key on the root |
With Livewire
Wrap the wizard in a form and make the last step's button type="submit"; the fields of all steps are validated together.
<form wire:submit="save">
<zb:stepper :steps="['project' => 'Project', 'team' => 'Team', 'confirm' => 'Confirmation']">
<zb:stepper.step name="project"><zb:input wire:model="name" label="Project name" required /></zb:stepper.step>
<zb:stepper.step name="team"><zb:input wire:model="peopleCount" label="Number of people" type="number" /></zb:stepper.step>
<zb:stepper.step name="confirm">…</zb:stepper.step>
<div class="mt-6 flex justify-between">
<zb:button variant="white" data-stepper-previous class="group-data-first/stepper:invisible">Back</zb:button>
<zb:button data-stepper-next class="group-data-last/stepper:hidden">Next</zb:button>
<zb:button class="hidden group-data-last/stepper:inline-flex" type="submit">Save</zb:button>
</div>
</zb:stepper>
</form>
| Prop | Values |
|---|---|
type="submit" | Submits the form on the last step |
Props
The values the component takes. What are props and slots?
| Prop | Type | Default | Description |
|---|---|---|---|
steps | — | [] | key => title or key => ['title', 'description', 'icon'] |
current | — | null | Key of the step shown on open; the first step when empty |
variant | — | numbered | numbered · icons |
backward | boolean | true | A finished step can be reopened; false: the server leads the steps and a finished step stays closed |
wire:model / x-model | — | — | Binds the current step both ways; the component checks a step and moves on itself |
step: name | — | — | Key of the step (required); same as in steps |
data-stepper-next · data-stepper-previous | — | — | A button in the content: goes to the next / previous step |
data-step · data-first · data-last | — | — | On the root: the current step, on the first / last step (classes with group/stepper) |
Alpine: step | — | — | Key of the current step (the 2.x way, on a page with Alpine) |
Alpine: index, steps | — | — | Current position (zero-based) and the step keys |
Alpine: next(), previous() | — | — | Goes to the next / previous step |
Alpine: goTo(key) | — | — | Goes back to a finished step (while backward is true) |
Alpine: isFirst, isLast | — | — | true on the first / last step |
Slots: zb:stepper: zb:stepper.step items and buttons. zb:stepper.step: the step's content; attributes such as class are added to the step's container.
Developer notes
- Later steps are reached with the buttons only; the buttons need no Alpine.
- The root shows the current step with
data-stepand the first and last steps withdata-first/data-last:group-data-last/stepper:hiddenhides a button on the last step. - On pages with Alpine the 2.x style (
next(),isLast…) works too. - Steps are only hidden, not removed; an error in a hidden step shows when the user returns to it.