-
I have a table repeater working. However, I am inserting an extra action that will be used with the barcode scanner. The field is already ready and the action is already searching for the record in the database. The question is how do I add the item to the table repeater and then return to the empty field for the next scan. Furthermore, I would like that if the item already exists in the table repeater, it does not add a new one, adding one more to the quantity column. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
In all honesty, you might need a custom field for this functionality. I'm not totally sure it's doable out of the box. |
Beta Was this translation helpful? Give feedback.
-
Working now! ->action(function (array $data, \Awcodes\TableRepeater\Components\TableRepeater $component, \Filament\Forms\Components\Actions\Action $action, \Filament\Forms\Form $form): void {
$product = Product::find($data['id']);
$newUuid = $component->generateUuid();
$items = $component->getState();
foreach ($items as $uuid => $item) {
if ($item['product_id'] === null) {
unset($items[$uuid]);
}
if ($item['product_id'] == $product->id) {
$items[$uuid]['quantity'] += 1;
$updated = true;
}
}
if(!isset($updated)){
$items[$newUuid] = [
'product_id' => $product->id,
'quantity' => 1,
];
}
$component->state($items);
$form->fill();
$action->callAfter();
$action->sendSuccessNotification();
$action->halt();
}) |
Beta Was this translation helpful? Give feedback.
Working now!