dtr32221 2013-02-20 19:09
浏览 31

在CAutoComplete字段中选择多个值

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.

enter image description here

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..

enter image description here

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.

  • 写回答

1条回答 默认 最新

  • douliao5467 2013-02-21 07:24
    关注

    The default CAutoComplete cannot handle this at the moment but there is an extension that extends it's behaviour as a wrapper for CJuiAutotComplete. It works like the jQuery UI multitagging demo.

    Found this by typing your question into google and the first answer that came up was this one.

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大