简体   繁体   中英

Grocery CRUD : Auto-Insert corresponding value of a field after Dropdown has been selected

I have explored the new Grocery CRUD library & working on it easily. I am now stuck on a problem. I have a 2 tables with their fields-

name_table : id , Name , Item1, Price1

items_table : id, Item2, Price2

Now I can choose the field -(Item2) of items_table to be listed as a dropdown to name_table while adding the record using set_relation function. But how do i insert the value of Price2 --> Price1 after the front end user has selected a specific dropdown.

Please check below Image Link & help me

Visual Diagram

you can use:

$crud->callback_field('field', array($this, 'field_callback'));

and in field_callback function:

function field_callback($value = '', $primary_key = null)
{

    $returner = "<select name='field' ></select>
                    <script type='text/javascript'>
                    -- JS AJAX SCRIPT
                    </script>";
    return $returner;
}

in this way you make a custom field with custom ajax in front end for your custom action

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM