Toggle with modal confirm

Good afternoon, I am facing a situation where I need to call a confirmation modal, and this has to occur when clicking on the Toggle() component.
Solution:
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 👇
From An unknown user
Twitter
Jump to solution
3 Replies
LeandroFerreira
LeandroFerreira5mo ago
try this
Toggle::make('toggle')
->registerActions([
Action::make('toggleConfirmation')
->requiresConfirmation()
->action(function () {
//do something...
})
])
->live()
->afterStateUpdated(function (Page $livewire, Toggle $component) {
$livewire->mountFormComponentAction($component->getStatePath(), 'toggleConfirmation');
})
Toggle::make('toggle')
->registerActions([
Action::make('toggleConfirmation')
->requiresConfirmation()
->action(function () {
//do something...
})
])
->live()
->afterStateUpdated(function (Page $livewire, Toggle $component) {
$livewire->mountFormComponentAction($component->getStatePath(), 'toggleConfirmation');
})
José Everton
José EvertonOP5mo ago
Thanks, It's fails for me! But I managed to find another solution, showing the confirmation modal when saving.
protected function getSaveFormAction(): Action
{
$action = Action::make(__('Save'));
if ($this->record->is_active && $this->data['is_active'] != 1) {
$action->requiresConfirmation()
->modalDescription(__('Are you sure you want to save??'));

}
$action->action(function () {
$this->save();

return redirect()->route('filament.admin.resources.users.index');
});

return $action;
}
protected function getSaveFormAction(): Action
{
$action = Action::make(__('Save'));
if ($this->record->is_active && $this->data['is_active'] != 1) {
$action->requiresConfirmation()
->modalDescription(__('Are you sure you want to save??'));

}
$action->action(function () {
$this->save();

return redirect()->route('filament.admin.resources.users.index');
});

return $action;
}
Solution
LeandroFerreira
LeandroFerreira5mo ago
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 👇
From An unknown user
Twitter
Want results from more Discord servers?
Add your server