Problems With Cjuiautocomplete

Hello,

I’ve been trying to make the CJuiAutoComplete work for a while, but with no success.

This is my controller action:




public function actionSuggestionTest() {


 	$r = array(

            array("label"=>"Test 1", "value"=>"Test 1") ,

            array("label"=>"Test 2", "value"=>"Test 2") ,

            array("label"=>"Test 3", "value"=>"Test 3") ,

            array("label"=>"Test 4", "value"=>"Test 4") ,

        );


		echo CJSON::encode($r); 

		Yii::app()->end();

		

}



And here is the view:




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

	    'name'=>'test',

	    'value'=>"test",

            'sourceUrl'=>$this->createUrl('paper/suggestionTest'),

            'options'=>array(

            	'showAnim'=>'fold',

            	'minLength'=>'1',

            ),

        ));



Nothing happens when I type something.

Can anyone help?

Is it working fine with source instead of sourceurl example as below?

‘source’=>array(‘Test 1’,‘Test 2’,‘Test 3’),

Try this code




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

            'name'=>'test',

            'value'=>"test",

            'source'=>$this->createUrl('paper/suggestionTest'),

            'options'=>array(

                'showAnim'=>'fold',

                'minLength'=>'1',

            ),

        ));



then in the controller




      $arr = array();

      $arr = array(

            array("label"=>"Test 1", "value"=>"Test 1") ,

            array("label"=>"Test 2", "value"=>"Test 2") ,

            array("label"=>"Test 3", "value"=>"Test 3") ,

            array("label"=>"Test 4", "value"=>"Test 4") ,

      );

      echo CJSON::encode($arr);



Please check the action suggestionTest is added in access rules on that controller…

check this path


$this->createUrl('paper/suggestionTest'),

check using firebug console.

Hi guys, thanks for all the help.

This works fine:




'source'=>array('Test 1','Test 2','Test 3'), 



Adding $arr = array(); does not solve the problem.

The action is in the access rules.

Firebug gave me a clue. When I type something, I receive an error "JSON.parse: unexpected non-whitespace character after JSON data", while executing


 

if ( window.JSON && window.JSON.parse ) {

return window.JSON.parse( data );

}



The data contents is:

"[{"label":"Test 1","value":"Test 1 a"},{"label":"Test 2","value":"Test 2 b"},{"label":"Test 3","value":"Test 3 c"},{"label":"Test 4","value":"Test 4 d"}]</br></br></br></br>"

Can I suppose the error is in the


</br>

at the end? How do I avoid this?

Hey, I figured out the problem!

I’m using the CWebLogRoute to debug my application. It inserts the <br> at the end of each page, even calling Yii::app()->end(); in the action.

Looking for a solution, I’ve found this: disable-yii-log-action-controller.

Basically, I disabled any log route by doing:




foreach (Yii::app()->log->routes as $route) {   

        if ($route instanceof CWebLogRoute || $route instanceof CFileLogRoute || $route instanceof YiiDebugToolbarRoute) {   

            $route->enabled = false;

        }   

} 



Again, many thanks for the help!