Use `cloneAction` to only clone one column

How can i use the cloneAction method to only clone for example the product_id and not the amount ordered in a repeater? I am trying to figure it out from here: https://filamentphp.com/docs/3.x/forms/fields/repeater#cloning-items It accepts a closure but I am not sure how to work out the closure. I am stuck here:
->cloneable()
->cloneAction(fn (Action $action) => tap($action, fn ($action) => ray($action)))
->cloneable()
->cloneAction(fn (Action $action) => tap($action, fn ($action) => ray($action)))
Thanks
Solution:
For anyone interested I worked it out: ```php ->cloneAction(fn (Action $action) => $action->action(function ($livewire, $component) {...
Jump to solution
1 Reply
Solution
JJSanders
JJSanders6mo ago
For anyone interested I worked it out:
->cloneAction(fn (Action $action) =>
$action->action(function ($livewire, $component) {
$items = $component->getState();
$originalItem = end($items);

$clonedItem = array_merge($originalItem, [
'id' => null,
'quantity' => null,
'reference' => null,
'delivered_quantity' => null,
'type' => null,
'remarks' => null,
]);

$items[] = $clonedItem;
$component->state($items);

return $items;
}))
->cloneAction(fn (Action $action) =>
$action->action(function ($livewire, $component) {
$items = $component->getState();
$originalItem = end($items);

$clonedItem = array_merge($originalItem, [
'id' => null,
'quantity' => null,
'reference' => null,
'delivered_quantity' => null,
'type' => null,
'remarks' => null,
]);

$items[] = $clonedItem;
$component->state($items);

return $items;
}))
Want results from more Discord servers?
Add your server