F
Filament9mo ago
cakan

Refresh repeater from child field

I have a Repeater that displays a list of documents. Each document is represented as a custom section with it's own delete button. But when I delete a record, repeater doesn't refresh. How do I refresh repeater from the child component? This is what I have tried but with no luck.
Repeater::make('documents')
->relationship()
->live()
->deletable(false)
->addable(false)
->registerListeners([
'refreshDocuments' => [
function (Repeater $component): void {
dd('test');
},
],
])
->schema([
Document::make('document_path')
->live()
->registerActions([
\Filament\Forms\Components\Actions\Action::make('deleteDocument')
->requiresConfirmation()
->action(function ($action, $record) {
$record->delete();
})
->after(fn ($livewire) => $livewire->dispatch('refreshDocuments'))
])
])
Repeater::make('documents')
->relationship()
->live()
->deletable(false)
->addable(false)
->registerListeners([
'refreshDocuments' => [
function (Repeater $component): void {
dd('test');
},
],
])
->schema([
Document::make('document_path')
->live()
->registerActions([
\Filament\Forms\Components\Actions\Action::make('deleteDocument')
->requiresConfirmation()
->action(function ($action, $record) {
$record->delete();
})
->after(fn ($livewire) => $livewire->dispatch('refreshDocuments'))
])
])
When I add new document, repeater refreshes. But when I delete it, it remains in the Repeater.
8 Replies
رجل الجمبري
Did you find a solution?
Mikail
Mikail2mo ago
Hey man. Have you gotten a solution to this?
LeandroFerreira
LeandroFerreira2mo ago
Shouldn't deletable do that?
Mikail
Mikail2mo ago
a custom delete from ->deleteAction() which works but need to refresh the repeater component
awcodes
awcodes2mo ago
But the repeater is a relationship, the default delete action should handle it by default. Keeping in mind though that the repeater will not persist the delete until the form is saved. But the default will remove it from the array via JS until it is saved.
Mikail
Mikail2mo ago
yes that works exactly has intented. But there was a need to allow deletion only on certain condition, hence the deleteAction() for manual delete. Which works fine except it doesn't remove it from array via JS. But it'd already be removed from the table.
awcodes
awcodes2mo ago
At least in my mind the condition delete might be better handled in a policy. But I could be wrong. I think the underlying issue you’re running into though is that the state on delete, is handled via js vs an actual server call. Thus the state isn’t getting updated at the livewire level and not resulting in a dom diff.
Mikail
Mikail2mo ago
yes but in my case i do not want to take it to authorization level exactly. is there a way to refresh the state after delete?
Want results from more Discord servers?
Add your server