CJuiAutoComplete sourceUrl

do somebody have any example on how to use CjuiAutoComplete with sourceUrl?

i read it from the documentation that it could get ajax response by using sourceUrl.

but still no demo though. thks :)

I am working on figuring this out, and I found this


You can do like this

      $arr = array();

      foreach($models as $model)


        $arr[] = array(

          'label'=>$model->some_attr,  // label for dropdown list

          'value'=>$model->some_attr,  // value for input field

          'id'=>$model->id,            // return value from autocomplete



      echo CJSON::encode($arr);

Edit: ‘label’ is useful for presenting more details in the dropdown list eg. ‘name (pk)’.



	 $this->widget('zii.widgets.jui.CJuiAutoComplete', array(








I’am trying with CJuiAutoComplete but the value is not submitted with the form.

My example:


    $form=$this->beginWidget('CActiveForm', array(




echo $form->hiddenField($model, 'idperson');

echo $form->labelEx($model,'nombre');

$this->widget('zii.widgets.jui.CJuiAutoComplete', array(

          //  'name' => 'Daytrip[nombre]',

            'name' => 'nombre',

            'sourceUrl' => array('reservatandem/SuggestPerson'),

            'value' =>  $model->nombre,

            'options' => array(

                'showAnim' => 'fold',

                //remove if you dont need to store the id, like i do...

                'select' => 'js:function(event, ui){ jQuery("#Daytrip_idperson").val(ui.item["idperson"]); }'


            'htmlOptions' => array(

                'style'=>'height: 20px; width: 300px;',

                //'style' => 'height:20px; w'




echo CHtml::submitButton('Select');



in the controller

public function actionSeleccionaCliente()


    	$model=new Personas; //para seleccionar el cliente












		    	$this->_model = $model;









		$dropzone = Dropzones::model()->findByPk($iddropzone);







It works!

Thank you for this little but precious bit of code. :)

Dear Friends,

I still did not manage to understand well the field source.

Does the line 12 of the script down indicate exatamente what? a path to directory? or archive?

09	$this->widget('zii.widgets.jui.CJuiAutoComplete', array(

10	    'name'=>'test1',

11	    'value'=>'test21',

12	    'source'=>$this->createUrl('jui/autocompleteTest'),

13	    // additional javascript options for the autocomplete plugin

14	    'options'=>array(

15	            'showAnim'=>'fold',

16	    ),

17	));


In this case a URL. See the explanation here.