Wizard modal with custom modal content
I am passing data to a custom modal content which is a wizard. Custom data is showing when the modal opens, but when clicking on the button to go to the next step, I am loosing the custom data passed to the custom view. The goal is to perform a custom modal action based on the custom data. This action may be performed at every steps, not sure what am I missing. Ideas?
//sandbox.blade.php
<div>
@foreach ($participants as $participant)
<div>
{{ $participant->name }} - {{ $participant->email }}
</div>
{{ ($this->edit)(['participant' => $participant->id]) }}
@endforeach
<x-filament-actions::modals />
</div>//sandbox.blade.php
<div>
@foreach ($participants as $participant)
<div>
{{ $participant->name }} - {{ $participant->email }}
</div>
{{ ($this->edit)(['participant' => $participant->id]) }}
@endforeach
<x-filament-actions::modals />
</div>//advance.blade.php
<div>
$arguments : @json($arguments)
{{ $action->getModalAction('report') }}
</div>//advance.blade.php
<div>
$arguments : @json($arguments)
{{ $action->getModalAction('report') }}
</div>//Sandbox.php
class Sandbox extends Component implements HasActions, HasForms
{
use InteractsWithActions, InteractsWithForms;
public function editAction()
{
return Action::make('edit')
->fillForm(function (array $arguments) {
return Participant::find($arguments['participant'])->toArray();
})
->registerModalActions([
Action::make('report')
->action(fn (array $arguments) => Log::info('report', $arguments)),
])
->action(fn (array $arguments) => Log::info('action', $arguments)
)
->modalContent(fn (array $arguments, Action $action): View => view(
'filament.pages.actions.advance',
['arguments' => $arguments, 'action' => $action]
))
->steps([
Step::make('Name')
->schema([
TextInput::make('name'),
]),
Step::make('Email')
->schema([
TextInput::make('email'),
]),
]);
}
}//Sandbox.php
class Sandbox extends Component implements HasActions, HasForms
{
use InteractsWithActions, InteractsWithForms;
public function editAction()
{
return Action::make('edit')
->fillForm(function (array $arguments) {
return Participant::find($arguments['participant'])->toArray();
})
->registerModalActions([
Action::make('report')
->action(fn (array $arguments) => Log::info('report', $arguments)),
])
->action(fn (array $arguments) => Log::info('action', $arguments)
)
->modalContent(fn (array $arguments, Action $action): View => view(
'filament.pages.actions.advance',
['arguments' => $arguments, 'action' => $action]
))
->steps([
Step::make('Name')
->schema([
TextInput::make('name'),
]),
Step::make('Email')
->schema([
TextInput::make('email'),
]),
]);
}
}Solution
Hey @Patrick Boivin thanks for the hint, sometimes I just forgot I am inside a LW component! This is what I ended up with:
//Sandbox.php
class Sandbox extends Component implements HasActions, HasForms
{
use InteractsWithActions, InteractsWithForms;
public Participant $participant;
public function editAction()
{
return Action::make('edit')
->mountUsing(function (array $arguments, Form $form) {
$this->participant = Participant::find($arguments['id']);
$form->fill($this->participant->toArray());
})
->registerModalActions([
Action::make('report')
->action(fn () => Log::info('report', $this->participant)),
])
->action(fn () => Log::info('action', $this->participant)
)
->modalContent(fn (array $arguments, Action $action): View => view(
'filament.pages.actions.advance',
['arguments' => $arguments, 'action' => $action]
))
->steps([
Step::make('Name')
->schema([
TextInput::make('name'),
]),
Step::make('Email')
->schema([
TextInput::make('email'),
]),
]);
}
}//Sandbox.php
class Sandbox extends Component implements HasActions, HasForms
{
use InteractsWithActions, InteractsWithForms;
public Participant $participant;
public function editAction()
{
return Action::make('edit')
->mountUsing(function (array $arguments, Form $form) {
$this->participant = Participant::find($arguments['id']);
$form->fill($this->participant->toArray());
})
->registerModalActions([
Action::make('report')
->action(fn () => Log::info('report', $this->participant)),
])
->action(fn () => Log::info('action', $this->participant)
)
->modalContent(fn (array $arguments, Action $action): View => view(
'filament.pages.actions.advance',
['arguments' => $arguments, 'action' => $action]
))
->steps([
Step::make('Name')
->schema([
TextInput::make('name'),
]),
Step::make('Email')
->schema([
TextInput::make('email'),
]),
]);
}
}