F
Filament7d ago
Iron

How to close a modal with EditAction?

So, in my modal, which extends EditAction, i have a form, but i also have a delete button, clicking this does delete the entry, but the modal never closes. I have tried everything, dispatch event, close-modal event, cancelParentActions, nothing closes the modal, any suggestions?
1 Reply
Iron
IronOP7d ago
Here is the code i use for the button, i extend EditAction
$actions[] = Action::make('deleteEntry')
->label(__('Delete Entry'))
->color('red')
->action(function (Component $livewire) {
$entry = $this->getRecord();
try {
app(DeleteEntry::class)($entry);
Notification::make()->title(__(' Entry Deleted'))->success()->send();

$this->cancelParentActions();
$livewire->dispatch('refresh');
} catch (ValidationException $e) {
Notification::make()
->title(__('Deletion failed'))
->body(collect($e->errors())->flatten()->implode("\n"))
->danger()
->send();
$this->halt();
}
});
$actions[] = Action::make('deleteEntry')
->label(__('Delete Entry'))
->color('red')
->action(function (Component $livewire) {
$entry = $this->getRecord();
try {
app(DeleteEntry::class)($entry);
Notification::make()->title(__(' Entry Deleted'))->success()->send();

$this->cancelParentActions();
$livewire->dispatch('refresh');
} catch (ValidationException $e) {
Notification::make()
->title(__('Deletion failed'))
->body(collect($e->errors())->flatten()->implode("\n"))
->danger()
->send();
$this->halt();
}
});
Okay, for anyone else struggling, placing the delete action inside $this->extraModalFooterActions worked perfectly.

Did you find this page helpful?