Update a dependent editor form field
Update a dependent editor form field

I need to access the price which is included in the call back line 1, the set(val) on line 2 is returning with the id or label value of line 1 so I need to figure out how to extract the value.
response: {"label":"98997 (3.95)","value":"3.95"},
editor.dependent('order_items.bipad', function(val, data, callback) {
editor.field('order_items.cover').set(val);
editor.disable('order_items.cover');
});
Field::inst( 'order_items.bipad' )
->options( Options::inst()
->table( 'magazines' )
->value( 'id' )
->label( array('id','magName') )
->render(function ( $row ) {
return $row['id'].' ('.$row['magName'].')';
} )),
Field::inst( 'order_items.cover' )
->options( Options::inst()
->table( 'magazines' )
->value( 'magPrice' )
->label( array('id','magPrice') )
->render(function ( $row ) {
return $row['id'].' ('.$row['magPrice'].')';
} )),
This question has accepted answers - jump to:
This discussion has been closed.
Answers
You can access the options on xhr when they are loaded from the server, do something with them, save them to a global variable - whatever.
You are trying to save a price in order_items.cover and get this from a different table. I've not seen that before; normally people save foreign keys. But anyway.
"cover" will eventually contain a price but only AFTER it was selected (if this is a CREATE situation).
Assuming you are in an EDIT situation OR you have already picked a value for "cover" during CREATE you could do this:
Quite absurd isn't it: But where else do you want to take the price from? "bipad" doesn't contain a price, only "cover" will contain the price after selection ...
Thank you,
a little more code may have made it more clear.
the cover is only grabbed to allow a new event:
So only need brought in to allow me to establish a total based on draw.
The BIPAD is an index on a leftjoin.