F
Filamentβ€’13mo ago
Yohan

SaveFormAction : requiresConfirmation()

What I am trying to do : I just want to add a confirmation modal when the "save changes" button is clicked for My Edit{Resource}. To do that, I overrided the getSaveFormAction method (see code below) What I did : nothing and no errors in console or in the page Code :
php
<?php

namespace App\Filament\Resources\AdGroupResource\Pages;

use App\Filament\Resources\AdGroupResource;
use Filament\Actions\Action;
use Filament\Resources\Pages\EditRecord;

class EditAdGroup extends EditRecord
{
protected static string $resource = AdGroupResource::class;

protected function getHeaderActions(): array
{
return [];
}

protected function afterSave(): void
{
$this->dispatch('landing-page-saved');
}

protected function getSaveFormAction(): Action
{
return Action::make('save')
->label(__('filament-panels::resources/pages/edit-record.form.actions.save.label'))
->requiresConfirmation()
->submit('save')
->keyBindings(['mod+s']);
}
}
php
<?php

namespace App\Filament\Resources\AdGroupResource\Pages;

use App\Filament\Resources\AdGroupResource;
use Filament\Actions\Action;
use Filament\Resources\Pages\EditRecord;

class EditAdGroup extends EditRecord
{
protected static string $resource = AdGroupResource::class;

protected function getHeaderActions(): array
{
return [];
}

protected function afterSave(): void
{
$this->dispatch('landing-page-saved');
}

protected function getSaveFormAction(): Action
{
return Action::make('save')
->label(__('filament-panels::resources/pages/edit-record.form.actions.save.label'))
->requiresConfirmation()
->submit('save')
->keyBindings(['mod+s']);
}
}
Is there another way to accomplish that ?
4 Replies
LeandroFerreira
LeandroFerreiraβ€’13mo ago
GitHub
How to make confirmation modal before create in CreatePage Β· filame...
protected function beforeCreate(): void { Notification::make() ->warning() ->title('Attention') ->body('This will notify to all user!') ->persistent() ->actions([ Act...
Yohan
YohanOPβ€’13mo ago
Thanks @Leandro Ferreira ! I've managed to get it to work, in fact it seems to be the submit() method that's preventing the modal from being displayed, but I can't figure out why. Anyway thanks for your help πŸ™
LeandroFerreira
LeandroFerreiraβ€’13mo ago
try
return Action::make('customSave')
->label('Save')
->requiresConfirmation()
->action(fn () => $this->save());
return Action::make('customSave')
->label('Save')
->requiresConfirmation()
->action(fn () => $this->save());
not sure if ->submit(null) will work
Yohan
YohanOPβ€’13mo ago
It works like this too :
php protected function getSaveFormAction(): Action
{
return Action::make('save')
->label(__('filament-panels::resources/pages/edit-record.form.actions.save.label'))
->requiresConfirmation()
->modalDescription("If you change the associated landing page your current config will be lost")
->modalIconColor('danger')
->action(fn () => $this->save())
->keyBindings(['mod+s']);
}
php protected function getSaveFormAction(): Action
{
return Action::make('save')
->label(__('filament-panels::resources/pages/edit-record.form.actions.save.label'))
->requiresConfirmation()
->modalDescription("If you change the associated landing page your current config will be lost")
->modalIconColor('danger')
->action(fn () => $this->save())
->keyBindings(['mod+s']);
}
Want results from more Discord servers?
Add your server