Yii Framework Forum: Cjuiautocomplete Problem - Yii Framework Forum

Jump to content

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

Cjuiautocomplete Problem Rate Topic: -----

#1 User is offline   pjravs 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 06-February 14

Posted 27 February 2014 - 11:33 PM

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

#2 User is offline   alirz23 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 967
  • Joined: 08-August 12
  • Location:Durban, South Africa

Posted 28 February 2014 - 03:56 AM

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

} 
?>

1

#3 User is offline   pjravs 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 06-February 14

Posted 02 March 2014 - 08:15 PM

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()
{
$_SESSION['erc_tempId']= $_POST['ClientType_clntype_name'];
}

public function actionStoreclient()
{
$res = array();
$id = $_SESSION['erc_tempId'];
$qtxt ="SELECT clnt_name FROM erc_client WHERE clnt_name LIKE :clnt_name AND clnt_typeid = $id";
$command =Yii::app()->db->createCommand($qtxt);
$command->bindValue(":clnt_name", '%'.$_GET['term'].'%', PDO::PARAM_STR);
$res =$command->queryColumn();
echo CJSON::encode($res);
Yii::app()->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!
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