How to dynamicly show/hide certain wizard step based on choice?

This did not work Step::make('step') ->visible(fn ($get) => $get('show') === 'no') show field has ->live()
3 Replies
Zamion101
Zamion1014w ago
What is the type of show, is it a Select or another field? Also you typed ->livel() with an l before the parenthesis is it a typo?
blink
blinkOP4w ago
No typo in codebase. Type of show field does not matter, but value. I.e. I have select or toggle or soemthing named - show. within step I add placeholder, ->content(fn ($get) => $get('show')) (same as in comparison in step visibility ). when I update toggle,select etc I see value changes but step visibility stays same as was initially either hidden or visible I did test all version if you are pointing to == vs ===
Bonux
Bonux4w ago
I don't think you can actually hide the steps, but I know you can skip the steps based on previous conditions. I've made a logic below to skip a step, if based on X condition we don't need something. This might help to make similar logic of what you need.
Step::make('Manager approval')
->afterValidation(function ($livewire) {
// You could use the $get('foo') === 'bar' for the same logic approach
if ($this->data['manager_approval'] === true) {

// If manager approves, we can skip the reason for rejection as we don't need it.
$schema = $livewire->content;
$wizard = $schema->getComponents()[0];
$reflection = new ReflectionClass($wizard);
$property = $reflection->getProperty('currentStepIndex');
$property->setAccessible(true);
$property->setValue($wizard, 5); // Fourth Step::make() is the Reason for rejection so we go for the fifth one after it.

$livewire->dispatch('next-wizard-step', key: $wizard->getKey());
}
})
->schema([
Toggle::make('manager_approval')
->label('Approve?')
->required(),
]),

Step::make('Reason for rejection')
->schema([
Textarea::make('comment')
->rows(5)
->required(),
]),
Step::make('Manager approval')
->afterValidation(function ($livewire) {
// You could use the $get('foo') === 'bar' for the same logic approach
if ($this->data['manager_approval'] === true) {

// If manager approves, we can skip the reason for rejection as we don't need it.
$schema = $livewire->content;
$wizard = $schema->getComponents()[0];
$reflection = new ReflectionClass($wizard);
$property = $reflection->getProperty('currentStepIndex');
$property->setAccessible(true);
$property->setValue($wizard, 5); // Fourth Step::make() is the Reason for rejection so we go for the fifth one after it.

$livewire->dispatch('next-wizard-step', key: $wizard->getKey());
}
})
->schema([
Toggle::make('manager_approval')
->label('Approve?')
->required(),
]),

Step::make('Reason for rejection')
->schema([
Textarea::make('comment')
->rows(5)
->required(),
]),

Did you find this page helpful?