Repeater: How can I conditionally show/hide Delete button in Repeater?

I have multiple notes attached with per contact, so I am using Repeater. I want to make sure that if note is more than 2 days old then it cannot be deleted, otherwise delete it allowed. Thanks
6 Replies
yagrasdemonde
yagrasdemonde4mo ago
You should check (array $arguments, Repeater $component) inject in action button
devspecter
devspecter4mo ago
Thanks @yagrasdemonde I will look into it when I tried the following code, the problem is that even for new notes (which are not saved yet in db, for those also I am getting same id as of the item which is saved in db. Resulting in an issue where I am not able to hide the delete button conditionally (if record is not saved in db then show delete button otherwise do not)
Forms\Components\Repeater::make('notes')
->deletable(fn (Forms\Components\Repeater $component) => dump('id: ' . $component->getRecord()->id))
Forms\Components\Repeater::make('notes')
->deletable(fn (Forms\Components\Repeater $component) => dump('id: ' . $component->getRecord()->id))
I also tried following
->deleteAction(function (Forms\Components\Actions\Action $action) {
$action->visible(fn ($record) => dump($record->id));
})
->deleteAction(function (Forms\Components\Actions\Action $action) {
$action->visible(fn ($record) => dump($record->id));
})
@yagrasdemonde Thank you for your help.
devspecter
devspecter4mo ago
No description
toeknee
toeknee4mo ago
IS this a relationship repeater?
devspecter
devspecter4mo ago
yes @toeknee and I am just able to get the active repeater state using the following code
->extraAttributes(function (array $arguments, Forms\Components\Repeater $component) {
$items = $component->getState();
$activeItem = $items[$arguments['item']];
if (isset($activeItem['id']))
return ['class' => 'hidden'];
return [];
})
->extraAttributes(function (array $arguments, Forms\Components\Repeater $component) {
$items = $component->getState();
$activeItem = $items[$arguments['item']];
if (isset($activeItem['id']))
return ['class' => 'hidden'];
return [];
})
I am can also use
visible
visible
or
hidden
hidden
instead of
extraAttribute
extraAttribute
but for some reason visible/hidden are not actually hiding the delete button but just making it disabled.
devspecter
devspecter4mo ago
GitHub
Repeater conditional deletable per item · filamentphp filament · Di...
Hello Expert Can you guide me please on how to show delete action for selected Repeater items? I don't want to allow user to delete all items, some items are mandatory, so I want to remove the ...
Want results from more Discord servers?
Add your server
More Posts