Hello anyone, im confusing when im using CJuiAutoComplete, Where is the mistake from my code…
This is my code from in my controller
public function actionAutoproduct() {
$res =array();
if (isset($_GET['term'])) {
$qtxt ="SELECT insurance_product_name,insurance_product_code FROM tbl_pd_insurance_products WHERE insurance_product_name ILIKE :name";
$command =Yii::app()->db->createCommand($qtxt);
$command->bindValue(":name", '%'.$_GET['term'].'%', PDO::PARAM_STR);
$res =$command->queryAll();
$arr = array();
foreach ($res as $model)
{
$arr[] = array(
'insurance_product_code'=>$model['insurance_product_code'],
'insurance_product_name'=>$model['insurance_product_name'],
);
}
}
echo CJSON::encode($arr);
Yii::app()->end();
}
And This is my View
<?php echo $form->textField($model,'codeproduct',array('size'=>5,'id'=>'codeproduct')); ?>
<?php
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'name'=>'refproduct',
'source'=>$this->createUrl('site/autoproduct'),
'htmlOptions' => array('size'=>'40'),
'options'=>array('showAnim'=>'fold',
'select'=>'js:function(event, ui) {
$("#'.CHtml::activeId($model,'codeproduct').'").val(ui.item.insurance_product_code);
}',
),
));
?>
Thanks for ur helping