Set Key-Value Data from Custom Page

Hello - I have a custom page that implements a form. The page allows users to scan barcodes. I want those scanned barcodes to appear as the values in the cards field.
return $form
->schema([
TextInput::make('amount')
->prefix('$')
->numeric()
->required()
->default(10)
->minValue(1)
->maxValue(100),
KeyValue::make('cards')
->required()
->keyLabel('Card Number')
->valueLabel('Barcode')
->reactive()
])
->statePath('data');

public function addCard($barcode)
{
$barcode = preg_replace('/[^0-9]/', '', $barcode);

foreach ($this->data['cards'] as $card) {
if ($card == $barcode) {
return Notification::make()
->danger()
->title('Card Already Scanned')
->send();
}
}

$this->data['cards'][$this->cardNum] = $barcode;
$this->cardNum++;
}
return $form
->schema([
TextInput::make('amount')
->prefix('$')
->numeric()
->required()
->default(10)
->minValue(1)
->maxValue(100),
KeyValue::make('cards')
->required()
->keyLabel('Card Number')
->valueLabel('Barcode')
->reactive()
])
->statePath('data');

public function addCard($barcode)
{
$barcode = preg_replace('/[^0-9]/', '', $barcode);

foreach ($this->data['cards'] as $card) {
if ($card == $barcode) {
return Notification::make()
->danger()
->title('Card Already Scanned')
->send();
}
}

$this->data['cards'][$this->cardNum] = $barcode;
$this->cardNum++;
}
My page is correctly emitting the scan event to addCard, but I can't figure out how to dynamically set the cards array and get it to update on the page.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server