F
Filamentβ€’2mo ago
Chamitoxddd

Repeater limitation

I'm having an issue while adding a new feature to the repeater. I want to limit the delete functionality, since I don't need to delete the first repeater item but I do need to delete the others. I tried setting it up with deletable as mentioned in the documentation, but I couldn't achieve the desired result, because it takes the repeater in a general way This is my code:
Repeater::make('members')
->label(trans_choice('maintenance_order.form.worker.title', 2))
->schema([
Select::make('assigned_to')
->label(trans_choice('maintenance_order.form.worker.title', 1))
->options(function (Get $get, $state) {
...
})
->searchable()
->default(fn($record) => ...)
->preload()
->disabled(function ($state, $component) use ($maintenanceOrder) {
$index = $component->getContainer()->getStatePath(false);
$index = (int) str_replace('members.', '', $index);
return $index === 0 && $state === $maintenanceOrder->assigned_to;
})
->dehydrated(),

TextInput::make('time')
->label(__('pulse.maintenance_order.real_execution_time'))
->numeric()
->suffix(trans_choice('common.hour', 0))
->default(fn() => $maintenanceOrder->real_execution_time),
])
->reorderable(false)
->columns(2)
->addActionLabel(__('maintenance_order.form.worker.attach'))
->visible(fn($get) => $get('add_members') === true),
Repeater::make('members')
->label(trans_choice('maintenance_order.form.worker.title', 2))
->schema([
Select::make('assigned_to')
->label(trans_choice('maintenance_order.form.worker.title', 1))
->options(function (Get $get, $state) {
...
})
->searchable()
->default(fn($record) => ...)
->preload()
->disabled(function ($state, $component) use ($maintenanceOrder) {
$index = $component->getContainer()->getStatePath(false);
$index = (int) str_replace('members.', '', $index);
return $index === 0 && $state === $maintenanceOrder->assigned_to;
})
->dehydrated(),

TextInput::make('time')
->label(__('pulse.maintenance_order.real_execution_time'))
->numeric()
->suffix(trans_choice('common.hour', 0))
->default(fn() => $maintenanceOrder->real_execution_time),
])
->reorderable(false)
->columns(2)
->addActionLabel(__('maintenance_order.form.worker.attach'))
->visible(fn($get) => $get('add_members') === true),
No description
3 Replies
itsmisce
itsmisceβ€’2mo ago
Up
BackDropGuy
BackDropGuyβ€’2mo ago
Maybe something like this? ->deleteAction(function (Action $action) { $action->visible(function (array $arguments, Repeater $component): bool { $itemKey = $arguments['item']; $keys = array_keys($component->getState() ?? []); $first = $keys[0] ?? null; return $itemKey !== $first; }); })
Chamitoxddd
ChamitoxdddOPβ€’2mo ago
I've used item and it worked... thanks πŸ‘ πŸ™Œ

Did you find this page helpful?