F
Filament2mo ago
tuseto

How to listen for repeater delete item action

I want to catch when one of repeater items is deleted in custom javascript file. Is there event dispatched ?
Solution:
No, I don't think so. You could overwrite the DeleteAction on the repeater and fire an event.
Jump to solution
4 Replies
Solution
Dennis Koch
Dennis Koch2mo ago
No, I don't think so. You could overwrite the DeleteAction on the repeater and fire an event.
tuseto
tusetoOP2mo ago
Thank you @Dennis Koch So here is the solution:
->deleteAction(fn(Action $action) => $action->after(fn(EditGarmentModel $livewire) => $livewire->dispatch('repeater::deleted')))
->deleteAction(fn(Action $action) => $action->after(fn(EditGarmentModel $livewire) => $livewire->dispatch('repeater::deleted')))
I have one more so to say problem. Now in the front-end I should push the code in the call stack because the event is fired before the UI is updated and my JS calculations rely on the ui.
Livewire.on("repeater::deleted", (event) => {
setTimeout(() => {
this.calculatePricing();
this.calculateTestPricing();
}, 0);
});
Livewire.on("repeater::deleted", (event) => {
setTimeout(() => {
this.calculatePricing();
this.calculateTestPricing();
}, 0);
});
Is there any smarter solution?
Dennis Koch
Dennis Koch2mo ago
You can use $get method inside components do stuff based on inputs. Probably the cleaner way. https://filamentphp.com/docs/4.x/schemas/primes#using-javascript-to-determine-the-content-of-the-text
tuseto
tusetoOP2mo ago
Thank you

Did you find this page helpful?