Unable to add form actions to modal

Hi, I've got a resource with a simple form for creating / editing. I've got a table that displays all the items on the index. Each row in the table has an edit button that opens the edit page in a modal slideover. At the bottom there is a "Save changes" and "Cancel" button. I'd like to add an additional button to the bottom, but I'm unable to get it to show. I added the below to my EditItem.php in the Resource Pages directory and the button didn't show.
protected function getFormActions(): array
{
return [
...parent::getFormActions(),
Action::make('foo')->action('bar'),
];
}
protected function getFormActions(): array
{
return [
...parent::getFormActions(),
Action::make('foo')->action('bar'),
];
}
I also tried getModalActions which made no difference. If I change the page to be a separate page rather than a modal, the button does appear - but that's not what I want. I'm at a loss, so any ideas welcome. Thanks
3 Replies
Adam Holmes
Adam HolmesOP9mo ago
Thanks for the pointer in the right direction. I'm having trouble working out where to put this block though. Should it be on my table action?
public static function table(Table $table): Table
{
return $table
--- SNIP ---
->actions([
Tables\Actions\EditAction::make()
->extraModalFooterActions(fn (Action $action): array => [
$action->makeModalSubmitAction('createAnother', arguments: ['another' => true]),
]),
])
--- SNIP ---
]);
}
public static function table(Table $table): Table
{
return $table
--- SNIP ---
->actions([
Tables\Actions\EditAction::make()
->extraModalFooterActions(fn (Action $action): array => [
$action->makeModalSubmitAction('createAnother', arguments: ['another' => true]),
]),
])
--- SNIP ---
]);
}
When I do that the type is wrong...
App\Filament\Resources\ListItemResource::App\Filament\Resources\{closure}(): Argument #1 ($action) must be of type Filament\Actions\Modal\Actions\Action, Filament\Tables\Actions\EditAction given, called in /var/www/html/vendor/filament/support/src/Concerns/EvaluatesClosures.php on line 35
App\Filament\Resources\ListItemResource::App\Filament\Resources\{closure}(): Argument #1 ($action) must be of type Filament\Actions\Modal\Actions\Action, Filament\Tables\Actions\EditAction given, called in /var/www/html/vendor/filament/support/src/Concerns/EvaluatesClosures.php on line 35
I can't think where else it should be as the modals are generated using slideOver and so I've not had to create any actions etc, it's all just worked "out the box" Thanks Ahhh - looks like I just needed to namespace the table action. Thanks!
mrvn
mrvn8mo ago
I am trying to achieve almost the same but is there a way to add a simple action button to the modal which excecutes some code without confirming or canceling the modal itself? I would just have a button which triggers an api call but ->action(() => ...) is not fired but using ->url(...) does:
TextInput::make('report_url'),
Actions::make([
Action::make('record')
->modalContent(function (Get $get) {
return view('iframe', ['url' => $get('remote_url')]);
})
->extraModalFooterActions(function (Get $get) {
$url = $get('report_url');
return [
ActionsAction::make('report')->action(fn () => dump('hi'))
];
})
->slideOver()
->mountUsing(function (Set $set, Get $get) {
$url = $get('settings.scope.url');
})
->modalCancelAction(function (Get $get) {
Http::get($get('url'));
})
->action(function (Set $set, Get $get) {
Http::get($get('test_url'));
})
])
TextInput::make('report_url'),
Actions::make([
Action::make('record')
->modalContent(function (Get $get) {
return view('iframe', ['url' => $get('remote_url')]);
})
->extraModalFooterActions(function (Get $get) {
$url = $get('report_url');
return [
ActionsAction::make('report')->action(fn () => dump('hi'))
];
})
->slideOver()
->mountUsing(function (Set $set, Get $get) {
$url = $get('settings.scope.url');
})
->modalCancelAction(function (Get $get) {
Http::get($get('url'));
})
->action(function (Set $set, Get $get) {
Http::get($get('test_url'));
})
])

Did you find this page helpful?