Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
- Laravel 13 mit Filament 5 (Admin), Inertia 3 + Vue 3 + Vuetify 4 (Material 3) - Anmeldung über Fortify (Login, Passwort vergessen/ändern), keine Selbstregistrierung - Profil mit Profilbild (WebP in festen Größen), Personenseiten, Header mit Avatar-Menü - Material-3-Farbschema aus der Primärfarbe, hell/dunkel/System pro Person - Basis-Branding (Portalname, Logo, Primärfarbe) im Admin unter „Erscheinungsbild“ - Benutzerverwaltung im Admin, Zugang vorläufig über is_admin - vendor/ (ohne Dev-Pakete) und Frontend-Build mitversioniert, Dev-Pakete in vendor-dev/ - PHPUnit-Tests gegen MySQL/MariaDB, Forgejo-CI-Matrix, Docker-Entwicklungsumgebung - VERSION, CHANGELOG.md und CONTRIBUTING.md mit Release-Ablauf Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
314 lines
10 KiB
Markdown
314 lines
10 KiB
Markdown
---
|
|
title: Wizards
|
|
---
|
|
import Aside from "@components/Aside.astro"
|
|
import AutoScreenshot from "@components/AutoScreenshot.astro"
|
|
import UtilityInjection from "@components/UtilityInjection.astro"
|
|
|
|
## Introduction
|
|
|
|
Similar to [tabs](tabs), you may want to use a multistep wizard to reduce the number of components that are visible at once. These are especially useful if your form has a definite chronological order, in which you want each step to be validated as the user progresses.
|
|
|
|
```php
|
|
use Filament\Schemas\Components\Wizard;
|
|
use Filament\Schemas\Components\Wizard\Step;
|
|
|
|
Wizard::make([
|
|
Step::make('Order')
|
|
->schema([
|
|
// ...
|
|
]),
|
|
Step::make('Delivery')
|
|
->schema([
|
|
// ...
|
|
]),
|
|
Step::make('Billing')
|
|
->schema([
|
|
// ...
|
|
]),
|
|
])
|
|
```
|
|
|
|
<AutoScreenshot name="schemas/layout/wizard/simple" alt="Wizard" version="5.x" />
|
|
|
|
<Aside variant="tip">
|
|
We have different setup instructions if you're looking to add a wizard to the creation process inside a [panel resource](../resources/creating-records#using-a-wizard) or an [action modal](../actions/modals#rendering-a-wizard-in-a-modal). Following that documentation will ensure that the ability to submit the form is only available on the last step of the wizard.
|
|
</Aside>
|
|
|
|
## Rendering a submit button on the last step
|
|
|
|
You may use the `submitAction()` method to render submit button HTML or a view at the end of the wizard, on the last step. This provides a clearer UX than displaying a submit button below the wizard at all times:
|
|
|
|
```php
|
|
use Filament\Schemas\Components\Wizard;
|
|
use Illuminate\Support\HtmlString;
|
|
|
|
Wizard::make([
|
|
// ...
|
|
])->submitAction(view('order-form.submit-button'))
|
|
|
|
Wizard::make([
|
|
// ...
|
|
])->submitAction(new HtmlString('<button type="submit">Submit</button>'))
|
|
```
|
|
|
|
Alternatively, you can use the built-in Filament button Blade component:
|
|
|
|
```php
|
|
use Filament\Schemas\Components\Wizard;
|
|
use Illuminate\Support\Facades\Blade;
|
|
use Illuminate\Support\HtmlString;
|
|
|
|
Wizard::make([
|
|
// ...
|
|
])->submitAction(new HtmlString(Blade::render(<<<BLADE
|
|
<x-filament::button
|
|
type="submit"
|
|
size="sm"
|
|
>
|
|
Submit
|
|
</x-filament::button>
|
|
BLADE)))
|
|
```
|
|
|
|
You could extract this component to a separate Blade view if you prefer.
|
|
|
|
<AutoScreenshot name="schemas/layout/wizard/submit-action" alt="Wizard with a submit button on the last step" version="5.x" />
|
|
|
|
## Setting a step icon
|
|
|
|
Steps may have an [icon](../styling/icons), which you can set using the `icon()` method:
|
|
|
|
```php
|
|
use Filament\Schemas\Components\Wizard\Step;
|
|
use Filament\Support\Icons\Heroicon;
|
|
|
|
Step::make('Order')
|
|
->icon(Heroicon::ShoppingBag)
|
|
->schema([
|
|
// ...
|
|
]),
|
|
```
|
|
|
|
<UtilityInjection set="schemaComponents" version="5.x">As well as allowing a static value, the `icon()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
|
|
|
<AutoScreenshot name="schemas/layout/wizard/icons" alt="Wizard with step icons" version="5.x" />
|
|
|
|
## Customizing the icon for completed steps
|
|
|
|
You may customize the [icon](#setting-up-step-icons) of a completed step using the `completedIcon()` method:
|
|
|
|
```php
|
|
use Filament\Schemas\Components\Wizard\Step;
|
|
use Filament\Support\Icons\Heroicon;
|
|
|
|
Step::make('Order')
|
|
->completedIcon(Heroicon::HandThumbUp)
|
|
->schema([
|
|
// ...
|
|
]),
|
|
```
|
|
|
|
<UtilityInjection set="schemaComponents" version="5.x">As well as allowing a static value, the `completedIcon()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
|
|
|
<AutoScreenshot name="schemas/layout/wizard/completed-icons" alt="Wizard with completed step icons" version="5.x" />
|
|
|
|
## Adding descriptions to steps
|
|
|
|
You may add a short description after the title of each step using the `description()` method:
|
|
|
|
```php
|
|
use Filament\Schemas\Components\Wizard\Step;
|
|
|
|
Step::make('Order')
|
|
->description('Review your basket')
|
|
->schema([
|
|
// ...
|
|
]),
|
|
```
|
|
|
|
<UtilityInjection set="schemaComponents" version="5.x">As well as allowing a static value, the `description()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
|
|
|
<AutoScreenshot name="schemas/layout/wizard/descriptions" alt="Wizard with step descriptions" version="5.x" />
|
|
|
|
## Setting the default active step
|
|
|
|
You may use the `startOnStep()` method to load a specific step in the wizard:
|
|
|
|
```php
|
|
use Filament\Schemas\Components\Wizard;
|
|
|
|
Wizard::make([
|
|
// ...
|
|
])->startOnStep(2)
|
|
```
|
|
|
|
<UtilityInjection set="schemaComponents" version="5.x">As well as allowing a static value, the `startOnStep()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
|
|
|
## Allowing steps to be skipped
|
|
|
|
If you'd like to allow free navigation, so all steps are skippable, use the `skippable()` method:
|
|
|
|
```php
|
|
use Filament\Schemas\Components\Wizard;
|
|
|
|
Wizard::make([
|
|
// ...
|
|
])->skippable()
|
|
```
|
|
|
|
Optionally, the `skippable()` method accepts a boolean value to control if the steps are skippable or not:
|
|
|
|
```php
|
|
use Filament\Schemas\Components\Wizard;
|
|
|
|
Wizard::make([
|
|
// ...
|
|
])->skippable(FeatureFlag::active())
|
|
```
|
|
|
|
<UtilityInjection set="schemaComponents" version="5.x">As well as allowing a static value, the `skippable()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
|
|
|
## Deferring the loading of step content
|
|
|
|
If the content of a wizard step is expensive to render, you can pass a `Schema` object to its `schema()` method and use `deferLoading()`. The content of the active step will be loaded when it enters the viewport. The content of a later step will not be loaded until the user reaches it:
|
|
|
|
```php
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Schemas\Components\Wizard;
|
|
use Filament\Schemas\Components\Wizard\Step;
|
|
use Filament\Schemas\Schema;
|
|
|
|
Wizard::make([
|
|
Step::make('Account')
|
|
->key('accountStep')
|
|
->schema(
|
|
Schema::make()
|
|
->components([
|
|
TextInput::make('name'),
|
|
])
|
|
->deferLoading(),
|
|
),
|
|
Step::make('Confirmation')
|
|
->key('confirmationStep')
|
|
->schema(
|
|
Schema::make()
|
|
->components([
|
|
// ...
|
|
])
|
|
->deferLoading(),
|
|
),
|
|
])
|
|
->key('accountWizard')
|
|
```
|
|
|
|
Every deferred schema must have a unique key. In this example, the keys on the steps are inherited by their child schemas, while the key on the `Wizard` component namespaces them from other steps in the same schema. You can learn more in the [schema overview](overview#deferring-the-loading-of-a-child-schema).
|
|
|
|
## Persisting the current step in the URL's query string
|
|
|
|
By default, the current step is not persisted in the URL's query string. You can change this behavior using the `persistStepInQueryString()` method:
|
|
|
|
```php
|
|
use Filament\Schemas\Components\Wizard;
|
|
|
|
Wizard::make([
|
|
// ...
|
|
])->persistStepInQueryString()
|
|
```
|
|
|
|
When enabled, the current step is persisted in the URL's query string using the `step` key. You can change this key by passing it to the `persistStepInQueryString()` method:
|
|
|
|
```php
|
|
use Filament\Schemas\Components\Wizard;
|
|
|
|
Wizard::make([
|
|
// ...
|
|
])->persistStepInQueryString('wizard-step')
|
|
```
|
|
|
|
<UtilityInjection set="schemaComponents" version="5.x">As well as allowing a static value, the `persistStepInQueryString()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
|
|
|
## Step lifecycle hooks
|
|
|
|
You may use the `afterValidation()` and `beforeValidation()` methods to run code before and after validation occurs on the step:
|
|
|
|
```php
|
|
use Filament\Schemas\Components\Wizard\Step;
|
|
|
|
Step::make('Order')
|
|
->afterValidation(function () {
|
|
// ...
|
|
})
|
|
->beforeValidation(function () {
|
|
// ...
|
|
})
|
|
->schema([
|
|
// ...
|
|
]),
|
|
```
|
|
|
|
<UtilityInjection set="schemaComponents" version="5.x">You can inject various utilities into the `afterValidation()` and `beforeValidation()` functions as parameters.</UtilityInjection>
|
|
|
|
### Preventing the next step from being loaded
|
|
|
|
Inside `afterValidation()` or `beforeValidation()`, you may throw `Filament\Support\Exceptions\Halt`, which will prevent the wizard from loading the next step:
|
|
|
|
```php
|
|
use Filament\Schemas\Components\Wizard\Step;
|
|
use Filament\Support\Exceptions\Halt;
|
|
|
|
Step::make('Order')
|
|
->afterValidation(function () {
|
|
// ...
|
|
|
|
if (true) {
|
|
throw new Halt();
|
|
}
|
|
})
|
|
->schema([
|
|
// ...
|
|
]),
|
|
```
|
|
|
|
## Using grid columns within a step
|
|
|
|
You may use the `columns()` method to customize the [grid](layouts#grid-system) within the step:
|
|
|
|
```php
|
|
use Filament\Schemas\Components\Wizard;
|
|
use Filament\Schemas\Components\Wizard\Step;
|
|
|
|
Wizard::make([
|
|
Step::make('Order')
|
|
->columns(2)
|
|
->schema([
|
|
// ...
|
|
]),
|
|
// ...
|
|
])
|
|
```
|
|
|
|
<UtilityInjection set="schemaComponents" version="5.x">As well as allowing a static value, the `columns()` method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.</UtilityInjection>
|
|
|
|
## Customizing the wizard action objects
|
|
|
|
This component uses action objects for easy customization of buttons within it. You can customize these buttons by passing a function to an action registration method. The function has access to the `$action` object, which you can use to [customize it](../actions/overview). The following methods are available to customize the actions:
|
|
|
|
- `nextAction()`
|
|
- `previousAction()`
|
|
|
|
Here is an example of how you might customize an action:
|
|
|
|
```php
|
|
use Filament\Actions\Action;
|
|
use Filament\Schemas\Components\Wizard;
|
|
|
|
Wizard::make([
|
|
// ...
|
|
])
|
|
->nextAction(
|
|
fn (Action $action) => $action->label('Next step'),
|
|
)
|
|
```
|
|
|
|
<UtilityInjection set="formFields" version="5.x" extras="Action;;Filament\Actions\Action;;$action;;The action object to customize.">The action registration methods can inject various utilities into the function as parameters.</UtilityInjection>
|