F
Filament9mo ago
_jimmy

Controlling modals in an action

Hi everyone. Does any one know how to control modals when calling a function like update within an action and have the modal NOT close after it does it's thing.
public function notesAction(): Action
{
return Action::make('notesAction')
->modalHeading('Edit Notes')

->fillForm(fn () => $this->fetchNotes())
->form($this->getFormFields())
->slideOver()

->action(fn (array $data) => $this->updateNotes($data));
}
public function notesAction(): Action
{
return Action::make('notesAction')
->modalHeading('Edit Notes')

->fillForm(fn () => $this->fetchNotes())
->form($this->getFormFields())
->slideOver()

->action(fn (array $data) => $this->updateNotes($data));
}
If the $this->updateNotes($data) errors out, I would like the modal and form to stay open so that the user can fix the issues. Right now it closes no matter the results.
Solution:
Figured it out. Just throw a halt exception, throw new Halt(); in your custom function from the Filament\Support\Exceptions\Halt namespace. In my case, the custom function was modified as:...
Jump to solution
3 Replies
johny7
johny79mo ago
Have you tried to use validation instead?
_jimmy
_jimmy9mo ago
so validation would work however, in this case, the $this->updateNotes method is a call to an api endpoint, which decides if success or not.
Solution
_jimmy
_jimmy9mo ago
Figured it out. Just throw a halt exception, throw new Halt(); in your custom function from the Filament\Support\Exceptions\Halt namespace. In my case, the custom function was modified as:
use Filament\Support\Exceptions\Halt;

public function updateNotes(string $notes)
{
try {
// call api endpoint
} catch (Exception $e) {
// log
// notify
throw new Halt();
}
}
use Filament\Support\Exceptions\Halt;

public function updateNotes(string $notes)
{
try {
// call api endpoint
} catch (Exception $e) {
// log
// notify
throw new Halt();
}
}
This prevents the modal from closing.