F
Filamentβ€’3mo 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β€’3mo ago
->visible()
kennyhorna
kennyhornaOPβ€’3mo ago
Hi πŸ‘‹ But this doesn't answer how to inject the element in the closure, that's the problem for me
toeknee
toekneeβ€’3mo ago
->visible(fn($record) => $record?->value)
awcodes
awcodesβ€’3mo 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
kennyhornaOPβ€’3mo 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
kennyhornaOPβ€’3mo ago
Thanks everyone for their help though πŸ‘ŒπŸ½. Have a nice weekend 😎
awcodes
awcodesβ€’3mo 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β€’3mo 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