I have given a CAutoComplete field in my form, and it's suggesting as per my query, now what I need is, after selecting a item from the suggestion box, if I put a comma and go for another item suggestion, then suggestions are working fine as per I have coded it like that, but selecting item is removing 1st item selected in the field and take it's place. What I want is, the items should be stay there as an input in the field.
after 1st select the field contains Nokia 100. Now after that if I put a ',' and again type something, then suggestion comes, and I also can select from them..
Selecting the new product is removing the previous one. How to get it like: Nokiaa 100, Micromax..., ... in the input box. Here's my code
<?php $this->widget('CAutoComplete', array(
'name'=>'ListModel[indexIds]',
'id'=>'input-box',
'attribute'=>'search',
'url'=> $this->createAbsoluteUrl('list/suggestions'),
'value'=>'',
'minChars'=>2,
'scroll'=>false,
'resultsClass'=>'searchAutoComplete ac_results',
'htmlOptions'=> array('class'=>"searchClickClear",'id'=>'select'),
'methodChain'=>'.result(function(){$("form#search-form").submit();})'
)); ?>
this is the input field
public function actionSuggestions() {
if(isset($_GET['q']) && ($keyword=trim($_GET['q']))!=='')
{
$what = $_GET['q'];
$what = explode(',', $what);
if(is_array($what))
$what = end($what);
$criteria = new CDbCriteria;
$criteria->select = array("product_name");
$criteria->condition = "product_name LIKE '%{$what}%' AND tagged = 1";
$criteria->group = "product_name";
$products = Production::model()->findAll($criteria);
$result = array();
if(count($products) > 0)
{
foreach($products as $p)
$result[] = $p->product_name;
echo implode("
",$result);
}
}
}
this is the suggestion part.