Cjuiautocomplete Problem

Good Day!

I need help in trying to figure out why the autocomplete showing all the data via ajax and not filtering it based on the user input. Here is my code.

For the View

<?php

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

‘name’=>‘clientName’,

‘id’=>‘clientName’,

‘source’=>$this->createUrl(‘updateclient’),

‘options’=>array(

));

?>

for the Controller

public function actionUpdateclient()

{

$data_value =array();

$data_value = array("red","green","blue","white","black");

echo CJSON::encode($data_value);

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

}

I want to test it before I use my dynamic model to it. Hope someone could help thanks!

Well I just modified your code I did not test Try this this should work.




<?php 


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

    'name'=>'clientName',

    'id'=>'clientName',

    'source'=>$this->createUrl('updateclient'),

    'options'=>array(

));     




// for the Controller


public function actionUpdateclient($term)

{

    $data = array("red","green","blue","white","black");

    $data = array_filter($data, function($item) use($term)

    {

        return preg_match("/{$term}/", $item);

    })

    echo CJSON::encode($data);

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


} 

?>

Alirz23 Thanks man for the help it did work. Issue has been solved.

I also tried working on database. here is my code just to share to you.

-VIEW-

<?php

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

‘name’=>‘clientName’,

‘id’=>‘clientName’,

‘source’=>$this->createUrl(‘storeclient’),

‘htmlOptions’=>array(‘class’=>‘span3’,‘style’=>‘margin-left:-8.6em’,‘placeholder’=>‘Select a Client Type First…’,‘id’ => ‘clientName’,),

‘options’=>array(

),

));

?>

-CONTROLLER-

public function actionUpdateclient()

{			


	&#036;_SESSION['erc_tempId']= &#036;_POST['ClientType_clntype_name']; 


}

public function actionStoreclient()

{			


	&#036;res = array();


	&#036;id = &#036;_SESSION['erc_tempId'];


	&#036;qtxt =&quot;SELECT clnt_name FROM erc_client WHERE clnt_name LIKE :clnt_name AND clnt_typeid = &#036;id&quot;;


    &#036;command =Yii::app()-&gt;db-&gt;createCommand(&#036;qtxt);


    &#036;command-&gt;bindValue(&quot;:clnt_name&quot;, '%'.&#036;_GET['term'].'%', PDO::PARAM_STR);


    &#036;res =&#036;command-&gt;queryColumn();


	echo CJSON::encode(&#036;res);


	Yii::app()-&gt;end(); 


}

note

The scenario here is the data is depending on a dropdown post in the method actionUpdateclient and it will pass a session variable in the actionStoreclient method for query.

I don’t know why the public variable I declared for this controller cannot handle the value of my post, So I decided to store it to Session. Hope it could help! Thanks!