Sorry to grab this old post, but it is exactly what I was looking for – and I can’t quite get it to work right…
I used Gii to set up my model so I did not write some of this*, but here is what I have:
views/NC/pobased/_form.php contains
...
<div class="row">
<?php
echo $form->labelEx($model,'PO_NUM'); ?>
<?php echo $form->textField($model, 'PO_NUM'
, array(
'ajax'=>
array('type'=>'GET'
, 'url'=>CController::createUrl( $this->id ."/changeStuff")
, 'dataType'=>'json'
, 'success'=>'function( myData ) {
$("#' . CHtml::activeId( $model, 'TOTAL_SIZE_LOT') .'" ).text(myData.tot_size_lot);
$("#' . CHtml::activeId( $model, 'TOTAL_SIZE_LOT') .'" ).refresh;
$("#' . CHtml::activeId( $model, 'VENDOR') .'" ).text(myData.vendor);
$("#' . CHtml::activeId( $model, 'VENDOR_NC_HANDLER') .'" ).text(myData.ven_nc_handler);
var o = $("#' . CHtml::activeId( $model, 'PART_NO') .'" );
for( var i in myData.part_nos ){
o.append($(\'<option></option>\').val(myData.part_nos[i]["ID"]).html(myData.part_nos[i]["NAME"]));
}
}'
) ) ); ?>
<?php echo $form->error($model,'PO_NUM'); ?>
</div>
and my PoBasedController is an instance of controllers/NC/HeadController.php which contains:
public function actionChangeStuff(){
$sql = <<<EOD
SELECT POLA.PART_NO as id
, CONCAT( CONCAT( POLA.PART_NO , ' - ' ), IP.DESCRIPTION )AS name
FROM IFSAPP.PURCHASE_ORDER_LINE_ALL POLA JOIN IFSAPP.INVENTORY_PART IP ON POLA.PART_NO = IP.PART_NO
WHERE POLA.ORDER_NO = '{$_REQUEST['Pobased']['PO_NUM']}'
EOD;
$connection = Yii::app()->db;
$command = $connection->createCommand($sql);
$data = $command->queryAll();
$ret= array(
'tot_size_lot' => 15,
'vendor' => "bob",
'ven_nc_handler' =>'monkeyboy',
'part_nos' => $data );
echo json_encode( $ret );
}
[OK, I confess that I have not finished getting the data from the DB for this, but that is easy.]
What happens when I run this in a browser is that none of my TextFields are updated, but my DropDownList works like a charm! Using Google Chrome’s Developer tools to step through the Javascript it shows that the TextField.textContent changes as expected to the values that I want it to, but they never “refresh” and show the data on the HTML page. What am I doing wrong?
Please advise.
Thanks,
Tim
*I am using an Oracle DB which uses all capitals for column and table names, so I when Gii set it up I was able to change my class names, but not my field/attribute names. I intend to clean this up, since it is soooo ugly to read, but I need it working first.