solutionforest / filament-unsaved-changes-bar
A floating Shopify / Laravel Cloud-style "Unsaved changes · Discard · Save" bar for Filament 5 panel forms.
Package info
github.com/solutionforest/filament-unsaved-changes-bar
pkg:composer/solutionforest/filament-unsaved-changes-bar
Requires
- php: ^8.3
- filament/filament: ^5.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/octane: ^2.6
- laravel/pint: ^1.14
- orchestra/testbench: ^9.5|^10.0|^11.0
- pestphp/pest: ^3.0|^4.0
- pestphp/pest-plugin-laravel: ^3.0|^4.0
- phpstan/phpstan-deprecation-rules: ^2.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-26 08:13:56 UTC
README
A floating "Unsaved changes · Discard · Save" bar for Filament 5 panel forms, in the style of Shopify and Laravel Cloud. It slides in as soon as a form is edited and disappears once the changes are saved, discarded, or typed back to their original values. If the user tries to leave with unsaved changes, a modal asks what to do with them.
Video: docs/images/demo.mp4
- Filament 5 (Livewire 4), PHP 8.3+.
- Works out of the box on every resource
EditRecordandCreateRecordpage, and on custom pages. - Leave modal: clicking a link while the form is dirty opens a modal with Save & leave, Discard & leave and Keep editing.
- Filament-native look: the bar is built from
<x-filament::button>and<x-filament::modal>. It follows your panel's colours and dark mode, and you can pick any registered Filament colour for the buttons. - Same dirty check as Filament: the hash is computed the same way as Filament's built-in alert, so the two never disagree.
- Field-safe: an untouched form with a RichEditor, FileUpload, Repeater or TagsInput never shows the bar.
- Multi-panel and Octane: each panel has its own configuration. The browser tests run under Laravel Octane (Swoole) in CI.
- Translations:
en,zh_TW,zh_CN.
Installation
composer require solutionforest/filament-unsaved-changes-bar php artisan filament:assets
Register the plugin on your panel:
use SolutionForest\FilamentUnsavedChangesBar\UnsavedChangesBarPlugin; public function panel(Panel $panel): Panel { return $panel // ... ->plugin(UnsavedChangesBarPlugin::make()); }
The bar now appears on all Edit and Create pages in that panel.
Recommended: add the trait
Add HasUnsavedChangesBar to a page to make Discard reset the form on the server, without a page reload:
use SolutionForest\FilamentUnsavedChangesBar\Concerns\HasUnsavedChangesBar; class EditPost extends EditRecord { use HasUnsavedChangesBar; }
| With the trait | Without the trait | |
|---|---|---|
| Dirty baseline | Server-side hash, refreshed after every save | Taken in the browser from the first rendered state |
| Discard | Refills the form from the record (Edit) or defaults (Create). No reload. | Asks in a Filament modal, then reloads the page |
Ctrl/⌘ + S saves while the bar is visible, with or without the trait.
Pages with several forms
Track every form's state path and reset them all on Discard:
use HasUnsavedChangesBar; public static function getUnsavedChangesBarStatePaths(): array { return ['profileData', 'notificationsData']; } protected function fillUnsavedChangesBarForms(): void { $this->profileForm->fill(/* saved values */); $this->notificationsForm->fill(/* saved values */); } /** Called by the bar's Save after every form validated, inside a DB transaction. */ protected function persistUnsavedChangesBar(array $states): void { // $states = ['profileData' => [...], 'notificationsData' => [...]] }
The bar's Save calls saveUnsavedChangesBar(): it validates every form first (one invalid form saves nothing and all errors show), persists via your persistUnsavedChangesBar() in one transaction, then refreshes the baseline. State paths map to forms by convention (profileData → profileForm); override getUnsavedChangesBarFormName() to change that. See demo/app/Filament/Pages/Preferences.php.
The browser's back / forward buttons are guarded in SPA mode too: the page stays put and the leave modal opens.
Options
Every option uses an enum or a Filament colour name, so a typo can't silently break it.
use SolutionForest\FilamentUnsavedChangesBar\Enums\BarPosition; use SolutionForest\FilamentUnsavedChangesBar\Enums\NavigationGuard; UnsavedChangesBarPlugin::make() ->position(BarPosition::Top) // BarPosition::Bottom (default) | BarPosition::Top ->navigationGuard(NavigationGuard::Modal) // Modal (default) | Shake | None ->saveButtonColor('success') // any Filament colour, default 'primary' ->discardButtonColor('danger') // any Filament colour, default 'gray' ->hideFormActionsWhenDirty() // hide the page's own Save/Cancel buttons while the bar is visible ->includePages([EditPost::class, StoreSettings::class]); // or ->excludePages([...]), not both
Leaving the page: navigationGuard()
| Mode | Clicking a link (sidebar, breadcrumb…), with or without panel ->spa() while dirty |
|---|---|
NavigationGuard::Modal (default) |
Opens a modal: Save & leave (saves, then navigates; stays if validation fails), Discard & leave, Keep editing |
NavigationGuard::Shake |
Stays on the page and shakes the bar |
NavigationGuard::None |
Doesn't intercept navigation |
Closing the tab or reloading the page always shows the browser's native "Leave site?" dialog. Browsers don't allow any custom UI there. Link clicks are intercepted before the browser navigates, so the modal also works on panels without SPA mode, and the user is never asked twice.
Choosing pages: includePages() / excludePages()
includePages([...])shows the bar only on the listed pages. It also enables custom pages that have asave()method.excludePages([...])shows the bar everywhere it's eligible except on the listed pages.- Calling both throws
ConflictingPageFilters, so the configuration can't be ambiguous. - To opt a single page out, add
protected bool $hasUnsavedChangesBar = false;to it.
Colours
The buttons are Filament's own button component. saveButtonColor() and discardButtonColor() accept any colour registered with Filament: primary, success, warning, danger, info, gray, or your own from FilamentColor::register(). The bar's surface follows Filament's cards: white in light mode, gray-900 in dark mode.
| Light | Dark | 2nd panel: top, success/danger, indigo theme |
|---|---|---|
![]() |
![]() |
![]() |
Translations
To change the labels, publish the translations:
php artisan vendor:publish --tag=filament-unsaved-changes-bar-translations
Multiple panels
Register the plugin on each panel that should show the bar. Each panel gets its own plugin instance, so the panels can be configured differently:
// AdminPanelProvider ->plugin(UnsavedChangesBarPlugin::make()) // ManagerPanelProvider ->plugin( UnsavedChangesBarPlugin::make() ->position(BarPosition::Top) ->navigationGuard(NavigationGuard::Shake) ->includePages([EditPost::class]) )
A panel without the plugin shows no bar. The demo has both panels (/admin and /manager), and both are covered by Pest and browser tests.
Laravel Octane
The plugin is safe under Octane:
- The plugin instance only holds configuration. Nothing request-specific is stored on it, and there's no static state.
- The render hook is registered through Filament's panel boot, which Filament resets on every request.
- The form state and hash live on the Livewire component.
CI runs the full Playwright suite against the demo served by Octane with Swoole (composer demo:octane), as well as against php artisan serve.
Custom pages
Any Filament page can show the bar if it:
- uses
InteractsWithFormsand binds its form with->statePath('data')to a public$dataarray, - has a save method (
saveby default), and - uses the
HasUnsavedChangesBartrait, or is listed in->includePages([...]).
class StoreSettings extends Page implements HasForms { use HasUnsavedChangesBar; use InteractsWithForms; public ?array $data = []; public function mount(): void { $this->fillForm(); } // Discard calls this to reload the saved values. public function fillForm(): void { $this->form->fill(StoreSetting::current()->only(['store_name', 'support_email'])); } public function save(): void { StoreSetting::current()->update($this->form->getState()); $this->rememberUnsavedChangesBarData(); // the bar hides after a successful save } }
If your save method has another name, override public static function getUnsavedChangesBarSaveMethod(): string. The full example is in demo/app/Filament/Pages/StoreSettings.php.
Compared with Filament's ->unsavedChangesAlerts()
Filament panels can already warn about unsaved changes with ->unsavedChangesAlerts(). That option is a warning only. This plugin adds a save bar and replaces the warning with a Filament-style modal. Both use the same check to decide whether the form has changed.
->unsavedChangesAlerts() |
This plugin | |
|---|---|---|
| Shows that the form has unsaved changes while editing | No | Floating bar |
| Save / Discard without scrolling to the form buttons | No | Yes, plus Ctrl/⌘+S |
| Leaving through a link (SPA mode) | Browser confirm() (OK / Cancel) |
Modal: Save & leave / Discard & leave / Keep editing |
| Leaving through a link (no SPA mode) | Browser "Leave site?" dialog | The same modal |
| Back / forward button (SPA mode) | Browser confirm() |
The same modal |
| Closing the tab or reloading | Browser "Leave site?" dialog | Browser "Leave site?" dialog |
| Tab close while an action modal has unsaved input | Warns | Not covered |
| Panel setting required | Yes | No |
You can use both. When both are on, the plugin handles navigation first and Filament's confirm() doesn't appear, so users are asked only once. Keep ->unsavedChangesAlerts() on as well if you want the warning for action modals.
How it works
- Server. The trait stores
md5(json_encode($data)), the same formula Filament'sHasUnsavedDataChangesAlertuses. It refreshes the hash when Filament callsrememberData()after a successful save. A failed validation leaves the hash unchanged, so the bar stays visible. - Browser. An Alpine component (
resources/dist/unsaved-changes-bar.js, no build step) watches$wire.data. It compares the data's hash with the server hash and shows the bar when they differ. - Navigation. The bar re-checks for changes at the moment you navigate, so typing and then clicking straight away is still caught.
- Initialising fields. FileUpload and RichEditor change
datawhile they load. 500 ms after load, if you haven't touched anything yet, the bar takes the current state as the new baseline.
Relation managers, table actions and modals
The bar tracks the page's main form ($data). Other components on the page don't need it:
- Relation manager and table actions save immediately. Create, edit and delete in a relation manager are written to the database when the action is submitted. There is never an "unsaved" state at page level.
- Action modals cover the page. While a modal is open you can't click the sidebar. For a warning on tab close while an action modal is open, also enable Filament's
->unsavedChangesAlerts()(see above). - If a relation should be part of the bar's Save, put it in the main form. Use
Repeater::make('items')->relationship(), orSelect::make('tags')->relationship()->multiple(). The relation then lives in$data, the bar tracks it, and Save saves it together with the record. The demo's Highlights repeater shows this nested-array case.
Limitations
- Closing the tab or reloading the page shows the browser's own dialog. No page can replace it with custom UI.
hideFormActionsWhenDirty()hides every.fi-sc-actionselement inside the page's<form>.
Demo and development
The demo/ folder contains two Filament panels:
/admin: the default configuration, with a Posts resource and a custom Store settings page./manager: the same Posts resource with the bar at the top, success/danger buttons and the shake guard.
It also contains the Playwright browser tests and the script that generates these screenshots and the video. See demo/README.md.
composer install composer demo # → http://127.0.0.1:8000/admin (demo@example.com / password) composer demo:octane # same app, served by Laravel Octane (Swoole) composer test # Pest composer analyse # Larastan (PHPStan level 10) composer format # Pint composer pun # Pun (format check + lint)
CI (.github/workflows/tests.yml) runs on GitHub-hosted runners. It runs:
- Pest on PHP 8.3–8.4,
- Larastan (PHPStan level 10), Pint and Pun (format check + lint), and
- the Playwright browser tests against the demo, served by both
php artisan serveand Octane (Swoole).
License
Released under the MIT License. Free to use, modify and distribute, including in commercial projects.






