在CAutoComplete字段中选择多个值

时间:2013-02-20 19:09:07

标签: php yii

我已经在我的表单中给出了一个CAutoComplete字段,根据我的查询建议,现在我需要的是,在从意见框中选择一个项目后,如果我输入逗号并转到另一个项目建议,那么建议按照我的编码方式正常工作,但选择项目是删除在字段中选择的第一个项目并取其位置。我想要的是,这些项目应该留在那里作为现场的输入。

enter image description here

在第一次选择之后,该字段包含诺基亚100.此后如果我输入','并再次输入内容,那么建议就会出现,我也可以从中选择..

enter image description here

选择新产品将删除上一个产品。如何得到它:诺基亚100,Micromax ......,...在输入框中。这是我的代码

<?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();})'
               )); ?>

这是输入字段

公共职能行动建议()         {

        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("\n",$result);
            }
        }
    }

这是建议部分。

1 个答案:

答案 0 :(得分:0)

默认CAutoComplete目前无法处理此问题,但有一个extension扩展了它作为CJuiAutotComplete包装器的行为。 它的工作方式类似于jQuery UI多标记演示。

通过在google中输入您的问题找到这个,并且出现的第一个答案就是这个。