Skip to content
This repository was archived by the owner on Mar 18, 2025. It is now read-only.

Commit 9a4397a

Browse files
committed
Add file-pond-clear event listener
1 parent 5383321 commit 9a4397a

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

docs/components/filepond.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,17 @@ the `file-pond` component adds a watcher on your `wire:model` by using `@entangl
145145
will pick up on those changes and remove the removed files from the FilePond instance.
146146

147147
You can opt out of this behavior by setting the boolean attribute `watch-value` to `false` on the component.
148+
149+
## Clear Event Listener
150+
151+
You may encounter some edge cases where you may need to clear the files out of the FilePond instance
152+
yourself. When using livewire, this can easily be accomplished by adding the following inside your
153+
component somewhere:
154+
155+
```php
156+
$this->dispatchBrowserEvent('file-pond-clear', ['id' => $this->id]);
157+
```
158+
159+
Each Livewire component has its own unique id assigned to it, so by passing `$this->id` into the
160+
event you're emitting, the component will be able to match the ids and clear the files for the correct
161+
component.

resources/views/components/files/file-pond.blade.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
<div wire:ignore
22
x-data="{ pond: null, @if ($shouldWatch($attributes)) value: @entangle($attributes->wire('model')), oldValue: undefined @endif }"
33
x-cloak
4+
x-on:file-pond-clear.window="
5+
const id = $wire && $wire.__instance.id;
6+
const sentId = $event.detail.id;
7+
if (id && (sentId !== id)) {
8+
return;
9+
}
10+
@if ($multiple)
11+
pond.getFiles().forEach(file => pond.removeFile(file.id));
12+
@else
13+
pond.removeFile();
14+
@endif
15+
"
416
x-init="
517
{{ $plugins ?? '' }}
618
@@ -32,7 +44,7 @@
3244
3345
this.oldValue = value;
3446
@else
35-
! value && pond.removeFile()
47+
! value && pond.removeFile();
3648
@endif
3749
});
3850
@endif

0 commit comments

Comments
 (0)