Dear Master of Yii,
My name is Chinmi, iam beginner in Yii.
i use widget zii.widgets.jui.CJuiAutoComplete to get nama and quantity from tbl_buku database.
and then also i want to automaticaly change another textfield quantity when i choose selected data nama from jcuiautocomplete.
here is program
//my controller BukuController.php
public function actionJudulbukulist(){
$sql = 'SELECT nama, quantity FROM tbl_buku WHERE nama LIKE :nbk';
$command = Yii::app()->db->createCommand($sql);
$command->bindValue(":nbk", '%'.$_GET['term'].'%', PDO::PARAM_STR);
$rows = $command->queryAll();
echo CJSON::encode($rows);
Yii::app()->end();
}
my view
<div class="">
<?php
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'name'=>'nama',
'sourceUrl'=>Yii::app()->createUrl('Buku/Judulbukulist'),
'options'=> array(
'minLength'=>2,
'type'=>'get',
'select'=>"js:function(event, ui) {
$('#Buku_quantity').val(ui.item.quantity);
}",
),
'htmlOptions'=>array(
'size'=> 100,
'style'=>'height:20px;',
),
));
?>
</div>
// have id= "Buku_quantity"
<div class=""><?php echo $form->textField($model,‘quantity’,array(‘size’=>4,‘maxlength’=>4));?></div>
i need help, why when i enter 2 letter pop up on the buttom cjuiautocomplete field only blank.
i try to see JSON from judulBukulist() function it return
[{"nama":"Buku Test","quantity":"280"},{"nama":"KURA - KURA","quantity":"950"}]
and then i try to remove quantity from sql syntac
$sql = ‘SELECT quantity FROM tbl_buku WHERE nama LIKE :nbk’;
return data
[{"nama":"KURA - KURA"},{"nama":"Buku Test"}]
it still not working it is the same when i enter 2 letter will popup blank
and then i try to change $rows = $command->queryAll(); with $rows = $command->queryColumn();
its return data
["KURA - KURA","Buku Test"]
it working when i enter 2 letrer pop up will show up
but it will not provide quantity data which i will use for change another texfield "Buku_quantity" id.
Please help me master…
thank you for your advice Master of Yii.
Regard,
Chinmi