Hi everyone. I’m trying to make the auto complete text box using CJuiAutoComplete. When I check the firebug, the ajax request returned correct results : [{“username”:“admin”},{“username”:“ASUS”},{“username”:“April”}], but they are not shown below the search box.
Here is the Controller :
public function actionAutoComplete() {
if (!empty($_GET['term'])) {
$sql = "SELECT username FROM tbl_user WHERE username LIKE '".$_GET['term']."%'";
$command = Yii::app()->db->createCommand($sql);
$qterm = $_GET['term'].'%';
$command->bindParam(":qterm", $qterm, PDO::PARAM_STR);
$result = $command->queryAll();
echo CJSON::encode($result);
exit;
} else {
return false;
}
}
And this is the form :
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'model'=>$model,
'attribute'=>'to',
'value'=>$this->createUrl('user/autoComplete'),
'source'=>$this->createUrl('user/autoComplete'),
'options'=>array(
'showAnim'=>'fold',
'minLength'=>'1',
'select'=>'js:function(event, ui) { console.log(ui.item.id +":"+ui.item.value); }'
),
));
If I set the source directly to be the array, for example array(‘Admin’,‘ASUS’,‘April’), then when the user type “a” for example, it is shown below the search box. Anyone has the solution ? Please advice. Thanks