Close modal manually

I have an action that runs some custom code and then saves the record. I want to validate the form first, before executing the code. If the validation fails, I want the modal to close. Right now, it doesn't. Can I trigger this manually?
protected function getHeaderActions(): array
{
return [
\Filament\Actions\Action::make('finish')
->icon('heroicon-o-check-circle')
->label(__('strings.strings.actions.mark_as_resolved'))
->requiresConfirmation()
->color('success')
->action(function ($record, $livewire) {

$livewire->validate(); // This validates the form correctly
//$livewire->dispatchBrowserEvent('close-modal'); ??

$record->status = 'published';
$record->publish_at = now();
$record->staging_vacancy->update(['status' => StagingVacancy::STATUS_REVIEW_FINALIZED]);
$record->save();

$this->redirect(StagingVacancyResource::getUrl());

}),

];
}
protected function getHeaderActions(): array
{
return [
\Filament\Actions\Action::make('finish')
->icon('heroicon-o-check-circle')
->label(__('strings.strings.actions.mark_as_resolved'))
->requiresConfirmation()
->color('success')
->action(function ($record, $livewire) {

$livewire->validate(); // This validates the form correctly
//$livewire->dispatchBrowserEvent('close-modal'); ??

$record->status = 'published';
$record->publish_at = now();
$record->staging_vacancy->update(['status' => StagingVacancy::STATUS_REVIEW_FINALIZED]);
$record->save();

$this->redirect(StagingVacancyResource::getUrl());

}),

];
}
1 Reply
Saade
Saade9mo ago
->action(function ($action, $record, $livewire) {
// ...

$action->cancel();
}),
->action(function ($action, $record, $livewire) {
// ...

$action->cancel();
}),