Hook for FileUpload field when file removed? (X Clicked to remove)
I have the following field:
It works when expected when uploading an image as
->afterStateUpdated()
is fired, however when I click the (X) to remove the photo the ->afterStateUpdated()
does not fire. Is there something I'm missing, or is there another hook I can use to run code when the image/upload is removed?12 Replies
What do you need to run? Until the form is saved it won’t be moved to permanent storage. And the tmp storage in livewire is garbage collected every 24 hours.
I'm trying to apply 'live' branding to a page so a user can see their edits in real time. When the image is removed I want to fire an event that re-sets a 'base/default' image immedatly so they can see what their settings current look like.
Ie, // do stuff here matters. 😆
Lol, indeed. Here is what I have for the 'adding the image' part. 🙂
That works exactly as intended. 🙂
It's when the image is removed, I cant get the afterStateUpdated() to fire. I've tried dd/dump to see if it was my dispatch stuff, but nothing fires.
Ok, so you’ll need something custom for that to allow for serving at least a blob since the tep directly isn’t publicly accessible.
Really all i need is a place to put code when the X is clicked. lol.
before saving that is.
I don’t think removing an item will triggering a Lw update in this context since the state at that point is managed on the alpine side.
Is it possible filepond has JS hooks that are fired when that x is clicked to remove the image? That could get me moving in the right direction I suppose.
I don’t think so, but dive the code.
Will do. I think I have a path forward. 🙂 Thank you @awcodes !
Found it!
Thanks again for your help!
Hi @CGM, I'm new to filament and wanted also to get the state when the image upload starts to disable some action buttons. Unfortunately, beforeStateUpdated is not supported by FileUpload component. Perhaps, I could use your solution, but I'm not sure how can I integrate that script. Thanks upfront!
ok, found out, I had to add into my AppServiceProvider.php:
And store script into my resources accordingly. Now need to figure out which events I need 🙂
@gds That's great! Here is where I found the event I needed.
https://pqina.nl/filepond/docs/api/instance/events/
Easy File Uploading With JavaScript | FilePond
A JavaScript library that can upload anything you throw at it, optimizes images for faster uploads, and offers a great, accessible, silky smooth user experience.