Can not get Value on preEdit Event

Can not get Value on preEdit Event

nusagatesnusagates Posts: 5Questions: 1Answers: 0

I want to set total_price from quanity * unit_price on preEdit event. I am using inline editing. But i can not get the quantity and unit_price value.

Here is my code:

 Editor::inst($db, 'carts')
            ->fields(
                Field::inst('products.name'),
                Field::inst('carts.quantity'),
                Field::inst('carts.unit_price'),
                Field::inst('carts.total_price'),
                Field::inst('carts.product_id')
                    ->options(Options::inst()
                        ->table('products')
                        ->value('id')
                        ->label('name')
                    )
            )
            ->on( 'preEdit', function ( $editor, $id, $values ) {
                $qty = $values['carts.quantity']*$values['carts.unit_price'];
                $editor
                    ->field( 'carts.total_price' )
                    ->setValue($qty );
            } )
            ->leftJoin("products", "carts.product_id", "=", "products.id")
            ->process($_POST)
            ->debug(true)
            ->json();

When i hit enter key after change value, i got this error: Undefined index: carts.quantity. What is wrong?

Replies

  • allanallan Posts: 64,133Questions: 1Answers: 10,581 Site admin

    Use $values['carts']['quantity']. Its a 2D array that gets submitted.

    Allan

  • nusagatesnusagates Posts: 5Questions: 1Answers: 0

    Done. Thanks Allan.

This discussion has been closed.