How can I check for any unsaved changes in the edit form?
I want to track when there are changes in the edit form. If no changes are made, I want the button to be disabled.
19 Replies
You can enable unsaved changes alert if that suits?
My use case is to disable the button while there is no changes yet to form fields, Sir.
Tried it like this but seems not working
I think you could do that in Alpine with something like:
(copied from
vendor/filament/filament/resources/views/components/page/unsaved-data-changes-alert.blade.php
)Solution
What about:
wire:dirty.class="enabled-class"
Should this be inserted inside extraAttr?
Yeah on the button yeah
Tested and approved. I think I'll use that too!
Here's how you'd use it @Nicole :
Oh, thanks, Sirs, I'll try.
By the way, this is the event?
wire:dirty.class
?
And this one a custom class?enabled-class
direct.class is native livewire event
wire:dirty
is a livewire directive:
https://livewire.laravel.com/docs/wire-dirty
And you should replace enabled-class
with any css class you wantLaravel
wire:dirty | Laravel
A full-stack framework for Laravel that takes the pain out of building dynamic UIs.
and enabled-class would be your tailwind or custom classes
Cool. It worked!
@toeknee @charlie I added
SpatieMediaLibraryFileUpload
, but when I remove or add a new image, wire:dirty
does not work. Any idea Sirs?Probably doesn't trigger a wire dirty because the form isn't dirty as it's a relationship. You could try setting after state updated a hidden field say 'ImagesUploaded' = true
I tried it like this
But still doesn't trigger wire:dirty
strange... then I am a little unsure
Is there any way to manually call
dirty
?
It seems it didn't consider this way $set('is_file_modified', true);
as dirty