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
->visible()
Hi π But this doesn't answer how to inject the element in the closure, that's the problem for me
->visible(fn($record) => $record?->value)
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.
@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 endThanks everyone for their help though ππ½. Have a nice weekend π
The native repeater delete action uses arguments. https://github.com/filamentphp/filament/blob/8ba4438f220c09baedd471b291b0ccb9aca2b4fa/packages/forms/src/Components/Repeater.php#L328
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
And table repeater just extends the core repeater.
I use @awcodes TableRepeater with ->disabled() but you can do the same with the original Repeater and ->visible()...