© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•10mo ago•
13 replies
frame

Prevent form from closing and show error on action form submit

Is it possible to prevent the form from closing and display an error message when an action form submit fails? I want to run a DB transaction in
->after
->after
(or another similar lifecycle method), and if it fails I don't want the form to submit, but instead show what went wrong.

Tables\Actions\Action::make('upload csv')
    ->form(function (Form $form) {
        return $form->schema([
            FileUpload::make('csv')
        ]);
    })
    ->after(function ($data, Component $livewire) use ($group) {
        $imports = Csv::readCsv($data['csv']->getPathName());
        $members = AddToGroup::addMembers($group, $imports); // throws
Tables\Actions\Action::make('upload csv')
    ->form(function (Form $form) {
        return $form->schema([
            FileUpload::make('csv')
        ]);
    })
    ->after(function ($data, Component $livewire) use ($group) {
        $imports = Csv::readCsv($data['csv']->getPathName());
        $members = AddToGroup::addMembers($group, $imports); // throws
Solution
Hmm I've been trying things out (throwing 💩 in the wall pretty much haha). Not sure if this is better or worse?
->action(function (Form $form, Action $action, $livewire) {
    throw ValidationException::withMessages([
        $form->getFlatFields()['foo']->getStatePath() => 'Something went wrong',
    ]);
->action(function (Form $form, Action $action, $livewire) {
    throw ValidationException::withMessages([
        $form->getFlatFields()['foo']->getStatePath() => 'Something went wrong',
    ]);

It feels like there should be a better way of doing this 🤔 Anyway, if it works...¯\_(ツ)_/¯
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Prevent Modal from closing on submit.
FilamentFFilament / ❓┊help
8mo ago
Is it possible to prevent a modal from closing on form submit?
FilamentFFilament / ❓┊help
3y ago
Prevent action modal from closing automatically
FilamentFFilament / ❓┊help
3y ago
How do i prevent an action modal from closing the modal on submit
FilamentFFilament / ❓┊help
2y ago