How can I conditionally show a confirmation modal during a resource edit form save.
Hello everyone,
I am struggling with this use-case:
What I am trying to do:
When an admin edits a user and removes a language from the "languages" relationship, I want to show a confirmation modal asking:
"Are you sure you want to remove this language from the user?"
If confirmed, proceed with the save. If canceled, return to the form with all current input preserved. If nothing is changed on the submit the warning should not pop up.
What I did:
I looked into using ->modalHidden(fn () => ...) on the action, and also tried to use ->before() on the action to handle conditional logic and show a notification on cancel.
I can't figure out how to intercept the save/update flow and inject a confirmation modal only if a language is removed, while still keeping the form state intact if the user cancels.
I have this in the EditUser.php
protected function getSaveFormAction(): Action
{
if ($this->shouldShowConfirmationModal()) {
return Action::make('save')
->label(('filament-panels::resources/pages/edit-record.form.actions.save.label'))
->action(function () {
$this->save();
})
->modalHeading(('app.messages.user_language_warning_text'))
->modalWidth(MaxWidth::Medium)
->requiresConfirmation();
} else {
return Action::make('save')
->label(__('filament-panels::resources/pages/edit-record.form.actions.save.label'))
->submit('save')
->keyBindings(['mod+s']);
}
}
But that seems to get called before the actual submit.
Anyone has a suggestion or can point me in the right direction?
Cheers, Tjardo
3 Replies
bump
Leandro Ferreira (@leandrocfe) on X
💡 Filament Tip: If you want to enhance the Create Form by adding a confirmation modal before submission, use the following code snippet 👇

X
That didn't workout for me. i managed to solve it different:
protected function getSaveFormAction(): Action
{
$data = $this->data;
$action = Action::make('save')
->label(('filament-panels::resources/pages/edit-record.form.actions.save.label'))
->action(function () {
$this->save();
});
if ($data['languages_removed']) {
$action->requiresConfirmation()
->modalHeading(('app.messages.user_language_warning_text'))
->modalWidth(MaxWidth::Medium);
}
return $action;
}
Thanks for taking the time to suggest a solution!