Yii Framework Forum: Problems With Cjuiautocomplete - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Problems With Cjuiautocomplete Rate Topic: -----

#1 User is offline   carlosraniery 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 19-July 13

Posted 24 September 2013 - 07:25 PM

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?
0

#2 User is offline   kumarkulandai 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 152
  • Joined: 18-November 11
  • Location:Bangalore

Posted 25 September 2013 - 01:17 AM

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

'source'=>array('Test 1','Test 2','Test 3'),
Regards,
Kumar Kulandai.

Posted Image
0

#3 User is offline   kumarkulandai 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 152
  • Joined: 18-November 11
  • Location:Bangalore

Posted 25 September 2013 - 01:22 AM

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);

Regards,
Kumar Kulandai.

Posted Image
0

#4 User is offline   Balu 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 153
  • Joined: 09-August 11
  • Location:Kerala, India

Posted 25 September 2013 - 01:30 AM

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

#5 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 894
  • Joined: 20-April 11
  • Location:India

Posted 25 September 2013 - 02:24 AM

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

check using firebug console.
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#6 User is offline   carlosraniery 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 19-July 13

Posted 25 September 2013 - 07:24 AM

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?
0

#7 User is offline   carlosraniery 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 19-July 13

Posted 25 September 2013 - 08:01 AM

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!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users