Multiple submit buttons in Action's modal

Hello! Is it possible with Filament admin panel to have multiple submit buttons in an Action's modal with different "values" to trigger different behaviors in the actual action closure? Some context: I have this Action on a table with a custom modal. In the action Closure I would access the submit "value" or some other info to determine which action to perform:
Action::make('my_action')
->modalContent(function (/* ... */) {
return view(/* ... */);
})
->form([
/* ... */
])
->action(function ($data) {
// Can I know here what submit was pressed? <---
// keep_first or keep_last?
})
->modalActions([
\Filament\Tables\Actions\Modal\Actions\Action::make('keep_first')
->submit(),
\Filament\Tables\Actions\Modal\Actions\Action::make('keep_last')
->submit(),
]),
Action::make('my_action')
->modalContent(function (/* ... */) {
return view(/* ... */);
})
->form([
/* ... */
])
->action(function ($data) {
// Can I know here what submit was pressed? <---
// keep_first or keep_last?
})
->modalActions([
\Filament\Tables\Actions\Modal\Actions\Action::make('keep_first')
->submit(),
\Filament\Tables\Actions\Modal\Actions\Action::make('keep_last')
->submit(),
]),
^ with this I'm able to show two different buttons which can submit the form but I don't know how to know which one was pressed Thanks in advance!
4 Replies
LeandroFerreira
Maybe
->action(function (array $data, Tables\Actions\Action $action) {
$action->getArguments(); //keep_first
})
->modalActions([
\Filament\Tables\Actions\Modal\Actions\Action::make('keep_first')
->action('callMountedTableAction', [
'actionFired' => 'keep_first'
]),
...
]),
->action(function (array $data, Tables\Actions\Action $action) {
$action->getArguments(); //keep_first
})
->modalActions([
\Filament\Tables\Actions\Modal\Actions\Action::make('keep_first')
->action('callMountedTableAction', [
'actionFired' => 'keep_first'
]),
...
]),
MrOlon
MrOlonOP2y ago
Thank you, it seems to work! Didn't read in the docs that $action can be injected! Can I ask where I can find some documentation on callMountedTableAction and similar, if exists?
LeandroFerreira
It isn't available on the docs, but you can check the Filament source code
MrOlon
MrOlonOP2y ago
Okay, thank you again!
Want results from more Discord servers?
Add your server