Hi, I’m a newbie and for days now I tried to make CJuiAutocomplete work and I can’t see what’s wrong. I’m using yii framework 1.1.3
Here’s my controller
public function actionAutocomplete()
{ $list=array();
if ((Yii::app()->request->isAjaxRequest ) && isset($_GET['term'])){
$list = Yii::app()->LDAP->listFullLDAP("'".$_GET['term']."'");
foreach ($list as $item){
$res[] = array(
'id' => $item['sn'].' '.$item['gn'],
'value' => $item['sn'].' '.$item['gn'],
'label' => $item['sn'].' '.$item['gn'],
'mail' => $item['ml'],
);
}
echo CJSON::encode($res);
Yii::app()->end();
}
}
My view
<div class="row right">
<?php echo $form->labelEx($model,'stagiaire'); ?>
<?php //echo $form->hiddenField($model,'stagiaire');
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'model'=>$model,
'attribute'=>'stagiaire',
'name'=>'FormInscription[stagiaire]',
/*'source'=>"js:function(request, response) {
$.getJSON('".$this->createUrl('FormInscription/autocomplete')."', {
term: extractLast(request.term)
}, response);
}",*/
'source'=>$this->createUrl('FormInscription/autocomplete'),
'htmlOptions'=>array('placeholder'=>'','autocomplete'=>'off'),
// additional javascript options for the autocomplete plugin
/*'options'=>array(
'minLength' => 2,
'autoFill'=>false,
'showAnim'=>'fold',
'select' => 'js:function(event, ui){
$("#FormInscription_stagiaire").val(ui.item.label);return false;}',
),*/
));?>
<?php echo $form->error($model,'stagiaire'); ?>
</div>
LDAP is a component I created to be able to connect with informations from OpenLDAP. I can easily view my informations in the view file
[{"id":"Bouwa Dzeakou Marcel","value":"Bouwa Dzeakou Marcel","label":"Bouwa Dzeakou Marcel","mail":"bomb@yahoo.fr "},{"id":"Bouwa Maka Olive","value":"Bouwa Maka Olive","label":"Bouwa Maka Olive","mail":"bomb@yahoo.fr "},{"id":"Bouwa Fonkoua Josephine","value":"Bouwa Fonkoua Josephine","label":"Bouwa Fonkoua Josephine","mail":"bomb@yahoo.fr "}]
When I put the array directly on the "source" property of the autocomplete, it shows, but when I pass through the controller nothing shows.
When I pass through the database, there’s no problem except that when I add javascript, nothing shows, even when add the “echo form hidden field”. As you can see I’ve commented out everything that concerns Javascript!
Please, I really, really, really need help. It’s urgent!