F
Filament10mo ago
Antoine

How to add requiresConfirmation() into modalSubmitAction() in Action

Hello, I have an action in my ListRecords page who open a modal and I need to have a modal of confirmation when the user click on the Button Submit.
Action::make('settings')
->form(...)
->action(...)
->modalSubmitAction(fn($action) => $action
->label('Enregistrer')
->requiresConfirmation() // this way doesn't work...
)
->modalCancelAction(fn($action) => $action->label('Fermer'));
Action::make('settings')
->form(...)
->action(...)
->modalSubmitAction(fn($action) => $action
->label('Enregistrer')
->requiresConfirmation() // this way doesn't work...
)
->modalCancelAction(fn($action) => $action->label('Fermer'));
It doesn't work because it's a StaticAction in modalSubmitAction(). How can I do that? Thanks
5 Replies
Patrick Boivin
Patrick Boivin10mo ago
Is this v2 or v3?
Antoine
Antoine10mo ago
This is for v3 I have a code like this who works but I can't get datas from parent form :
->modalSubmitAction(false)
->modalCancelAction(false)
->extraModalFooterActions([
Action::make('close')
->close(),
Action::make('save')
->requiresConfirmation()
->action(function (array $data) {
dd($data);
}),
])
->form(...)
->modalSubmitAction(false)
->modalCancelAction(false)
->extraModalFooterActions([
Action::make('close')
->close(),
Action::make('save')
->requiresConfirmation()
->action(function (array $data) {
dd($data);
}),
])
->form(...)
An idea? Or a method to call parent action?
Patrick Boivin
Patrick Boivin10mo ago
Try this:
Action::make('save')
->requiresConfirmation()
->action(function ($livewire) {
dd($livewire->mountedActionsData[0]);
}),
Action::make('save')
->requiresConfirmation()
->action(function ($livewire) {
dd($livewire->mountedActionsData[0]);
}),
Antoine
Antoine10mo ago
Thank's @Patrick Boivin, it works! I've find an another way to do that with : Add this action in modal with modalSubmitAction, etc... :
->action(function ($data) {
$this->replaceMountedAction('save', $data);
});
->action(function ($data) {
$this->replaceMountedAction('save', $data);
});
And create a function who called when the submit button triggered with passing $data to $arguments :
public function saveAction(): Action
{
return Action::make('save')
->requiresConfirmation()
->action(function (array $arguments) {
$data = $arguments;
dd($data
});
}
public function saveAction(): Action
{
return Action::make('save')
->requiresConfirmation()
->action(function (array $arguments) {
$data = $arguments;
dd($data
});
}
But I prefer your method! There is no cleaner native method to retrieve the parent's form? Or execute the parent's action from children like this :
Action::make('test')
->requiresConfirmation()
->executeParentAction()
Action::make('test')
->requiresConfirmation()
->executeParentAction()
Patrick Boivin
Patrick Boivin10mo ago
There is no cleaner native method to retrieve the parent's form?
I'm not really sure... nested actions are still new for me too