F
Filament3mo ago
Yash

Prevent Modal from closing on submit.

On my view page i have action which is a modal (slideover) and after submit i do not want to close the modal. how to achieve this. one way is to use extraModalFooterActions and disable the default action, but this is just a workaround and due to this the submit validation does not triggered. i need the proper solution for this
Action::make('notes')
->slideOver()
->closeModalByClickingAway(false)
->form(function (\Filament\Actions\Action $action) {
//INPUT AND FORM COMPONENTS
})
->action(function (Action $action, $record, array $data) {
//SAVING THE DATA
//DO NOT WANT TO CLOSE THIS MODAL/SLIDEOVER
})
Action::make('notes')
->slideOver()
->closeModalByClickingAway(false)
->form(function (\Filament\Actions\Action $action) {
//INPUT AND FORM COMPONENTS
})
->action(function (Action $action, $record, array $data) {
//SAVING THE DATA
//DO NOT WANT TO CLOSE THIS MODAL/SLIDEOVER
})
3 Replies
Adam
Adam3mo ago
You could try using the halt() method after you save your data:
$action->halt();
$action->halt();
I've used this before in the after() lifecycle hook:
Action::make('notes')
->after(fn (Action $action) => $action->halt())
Action::make('notes')
->after(fn (Action $action) => $action->halt())
Yash
YashOP3mo ago
thanks @Adam i tried this and somewhat it works but it created the other issue where the state of the modal content is not updating since it stopped the lifecycle , i can use something like
->after(callback: function (Action $action) {
$action->halt();
$action->getLivewire()->refresh();
}),
->after(callback: function (Action $action) {
$action->halt();
$action->getLivewire()->refresh();
}),
but it works wierdly, i have to sumit two time to make changes reflect.
Adam
Adam3mo ago
What is it exactly that you want to happen? You save the data and the modal remains open, and then you want the modal form to reset?

Did you find this page helpful?