FilamentF
Filament2y ago
82 replies
Sayy

how to get data from input with custom page

i want get my data from input like this, with wire:model
<x-table.td>
                                    <input
                                        class="w-15 text-xs h-8 dark:bg-zinc-800 dark:text-white rounded-md border shadow-sm border-zinc-200 dark:border-zinc-700"
                                        type="number"
                                        value="{{ $orderDetail->harga_awal }}"
                                        name="harga_awals"
                                        wire:model="harga_awals"
                                    />
                                </x-table.td>

and then i got error like this
Typed property App\Filament\Resources\TransaksiPembelianResource\Pages\CreateTransactionPembelian::$harga_awals must not be accessed before initialization

my resource like this already to iniatialization
class CreateTransactionPembelian extends Page implements HasForms
{
    use InteractsWithForms;

    protected static string $resource = TransaksiPembelianResource::class;

    protected static string $view = 'filament.resources.transaksi-pembelian-resource.pages.create-transaction-pembelian';

    public TransaksiPembelian $record;
    public mixed $selectedProduct;
    public int $quantityValue = 1;
    public int $discount = 0;
    public int $harga_awals;

    public function getTitle(): string
    {
        return "Kode Transaksi: {$this->record->transaksi_number}";
    }

    public function updateQuantity(TransaksiPembelianDetail $transaksiDetail, $quantity): void
    {
        if ($quantity > 0) {
            $transaksiDetail->update([
                'quantity' => $quantity,
                'harga_awal' => $this->harga_awals,
                //'discount' => $this->discount,
                'harga_akhir' => $transaksiDetail->harga_awal * $quantity,
            ]);
        }
    }

i just want to get data harga_awal and then calculate with harga_akhir then data will be show to custom page input
Solution
 <input class="w-15 text-xs h-8 dark:bg-zinc-800 dark:text-white rounded-md border shadow-sm border-zinc-200 dark:border-zinc-700"
        type="number"
        value="{{ $orderDetail->quantity }}"
        wire:change="updateQuantity({{ $orderDetail->id }}, $event.target.value)"
        min="1"
        max="{{ $orderDetail->product->stock_quantity }}" />
Was this page helpful?