F
Filamentβ€’2mo ago
kennyhorna

Conditionally displaying delete action in a Repeater based on row

Hello, My model has a "active" field that should enable/disable the deletion of the element in the repeater. I know that there's a ->deleteAction(fn ($action) => ...) function, but I haven't been able to figure out how to inject the current row. I tried with $state but the whole repeater array is included instead. Is there a way to accomplish this?
9 Replies
Matthew
Matthewβ€’2mo ago
->visible()
kennyhorna
kennyhornaβ€’2mo ago
Hi πŸ‘‹ But this doesn't answer how to inject the element in the closure, that's the problem for me
toeknee
toekneeβ€’2mo ago
->visible(fn($record) => $record?->value)
awcodes
awcodesβ€’2mo ago
The current rows key will be available as $arguments[β€˜item’] in the action callback for the delete action. So you can use that to get the item from the $state array.
kennyhorna
kennyhornaβ€’2mo ago
@awcodes thanks, but no, in the normal ->deleteAction() the $arguments variable is unresolvable. It is present though in custom actions inside the ->extraItemActions([...]) method. I ended up doing something like that to access the item at the end
No description
kennyhorna
kennyhornaβ€’2mo ago
Thanks everyone for their help though πŸ‘ŒπŸ½. Have a nice weekend 😎
awcodes
awcodesβ€’2mo ago
GitHub
filament/packages/forms/src/Components/Repeater.php at 8ba4438f220c...
A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS. - filamentphp/filament
awcodes
awcodesβ€’2mo ago
And table repeater just extends the core repeater.
micraux
micrauxβ€’2mo ago
I use @awcodes TableRepeater with ->disabled() but you can do the same with the original Repeater and ->visible()...
->deleteAction(
fn (Action $action) => $action
->disabled(function (array $arguments, TableRepeater $component): bool {
$items = $component->getState();
$active_item = $items[$arguments['item']];

return $active_item['active'];
})
->deleteAction(
fn (Action $action) => $action
->disabled(function (array $arguments, TableRepeater $component): bool {
$items = $component->getState();
$active_item = $items[$arguments['item']];

return $active_item['active'];
})
Want results from more Discord servers?
Add your server