Show a warning before leaving page when you have filled in a form (save/discard changes)
I have a large form where the save button is far down, sometimes people forget to press it and leave that page. Whatever they have filled in will be lost.. Is there any way to give a warning before leaving the page if there has been a field filled in.. I cannot find something in the docs
Solution:Jump to solution
GitHub
Wait, don't leave! · Issue #9992 · filamentphp/filament
Alert the user if they have unsaved changes in a form.
50 Replies
I have experimented with saving
->afterStateUpdated()
but that will impact performance in live (not worth it)I tried the same but didn’t find a proper solution. Alpine/LW tracks your dirty state but I don’t think you have access to that. Would be the ideal solution.
I see.. wont waste more time on it then lol
Thank you for the reply anyway :)
There is an option to make the footer sticky on the page too. That way the form actions would always be visible and the user wouldn’t have to scroll to the bottom of the page.
I guess you can always have a save action for each form section on a page right?
that sucks :P
I went with aw's idea for now haha
In my opinion I actually think that would be better design for a long form but oh well
yes.. but it will likely cause users to press save... for each section
Do your users usually have to edit every field on a long form each time they go to it?
no, but we use it for project management.. the form doubles for an information overview of the project :)
when the project is created all fields are filled in
Alright well for your use case then sure
There is?
I wrapped the button in a sticky div.. nothing fancy
I see, so you overwrote a core template to do this?
Or is it form builder standalone without panel?
Location shouldnt matter? forms render without a save button.. just make the button you are using sticky.. I am using the filament button to match the design
Well, the save button for resources in the panels get created by filament, not by me, so I'd have to adapt a core template to make it sticky
I think there's a plugin to make the header sticky, but not the footer with the save and cancel buttons
I am on v2.. have not used v3 yet so dunno about panels
soon xd
v2 has resources as well, but I guess you use custom forms outside the resources. Thanks anyway, it's a nice solution for that case.
Would still be great to have a 'you have unsaved changes' notice somehow 😄
read up in #👹┊off-topic , Dan said a PR would be welcome.. just no clue how it would be done haha
I think sticky footer is built into v3. Don’t know the API though.
Only for modals, I think
public static bool $formActionsAreSticky = false;
not sure it's in the docs
that just goes on the Page (create / edit)Hi guys. Very interesting conversation. I have the same need. Prevent users from leaving the form by displaying an alert message or something similar.
This is for v3. Right?
yes. it was also in v2
it's scroll based though so you won't see any affect unless your page it long enough to force a scroll
If you find something.. let us know 😂
So is not working for me. I added the code on my create page
Working in the demo. Maybe you have cached views
you also have to scroll the page for it to show up
It is most certainly not
but also doesnt work for me either
yea, i tried looking for it
it's working in the demo
make sure you're adding it to CreateRecord and EditRecord
it doesn't work on RecordResource
yeah, it's on the edit page, and there's the corresponding alpine and css in the page source now
But it's just not sticky 🤨
not sure what to tell you. lol.
maybe a plugin conflict with styles. ?
I tried "php artisan optimize:clear" but it still doesn't work
also tried on "true" value
No plugins right now. Maybe something else broke. Don't know if the demo always has the latest version. Anyways, that's not really a priority right now
Something like this should work to prevent the redirect:
And integrate it natively with Forms ?
Running 3.0.16 on my local version of the demo.
does not work for me:
resources\views\livewire\create-purchase-order-using-purchase-requisition.blade.php
What is the command to see that information?
No it wouldn't because you have doubled up the form.
php artisan about
thanks
Do you mean the declaration of <form> and {{ $this->form }} ?
Do forms have input events at all?
Anyone has made any progress/ideas on this? Otherwise I will give up and mark it as too much effort to implement haha
Im fine if it means writing something custom with alpine I just have no clue where I would put the code with
beforeunload
hey Josef, did you find a solution for this? can't get it to work
i think something got broken between versions, its not working on the demo anymore
hmm actually the check to wether it should stick or not, is a bit wrong, only works on small height screens (can be simulated by opening the devtools on the bottom of the page)
gonna PR a fix for it
Does anyone found a solution for this?
like a warning for the user before they leave?
@Dennis is working on something i guess (please dont go bother he asking when it will be released)
awesome, cant wait
Solution
something relevant
https://github.com/filamentphp/filament/issues/9992
GitHub
Wait, don't leave! · Issue #9992 · filamentphp/filament
Alert the user if they have unsaved changes in a form.
Dude. You just copy/pasted someone else's response in another thread ... and pretended it's your own!
Please get off this Discord server. Stop spamming in every thread.
Banned him.
☠️ legendary
but yes, I think this thread is solved and I will follow the development of this issue