How to know when a modal, opened via a Table action, has been closed?
I need to dispatch an event when a modal is closed. Right now I can do it when the "submit" button is clicked with
But I can not figure out how to do this on cancel. I've tried overriding by way of
modalFooterActions
with something like this:
This feels like progress because the correct code gets executed when the respective button gets clicked; however, it also feels like I'm moving backwards, because the modal doesn't automatically close like it would do out of the box using just action
. So I solve one problem but encounter a new 🙂
I thought that modalCancelAction
would be the way, but that is getting executed when the modal is being rendered so I must be misunderstanding its intention.Solution:Jump to solution
Ok. I think it’s because you’re trying to override the existing actions without actually replacing the existing submit and close that are already cached. Try this approach instead: https://filamentphp.com/docs/3.x/actions/modals#modifying-a-default-modal-footer-action-button
5 Replies
Add
$this->close();
after your dispatch.
Might need to pass in $action in the callback and call $action->close() in this context though.I tried this, but I get the same result:
The
Action
that I'm using here is Filament\Tables\Actions\Action
. I'm getting a little confused because StaticAction
, from what I can tell, is the only class that uses the CanClose
trait, but maybe my IDE is failing me here.Solution
Ok. I think it’s because you’re trying to override the existing actions without actually replacing the existing submit and close that are already cached. Try this approach instead: https://filamentphp.com/docs/3.x/actions/modals#modifying-a-default-modal-footer-action-button
Great - thanks! The code that is currently working is: