Yii 1.1: multicomplete

CJuiAutoComplete wrapper to create multi tags input field with any splitter, and autocomplete
20 followers

Multitagging autocomletion wrapper for CJuiAutoComplete.

Requirements

CJuiAutoComplete
Yii Framework >= 1.1.2

Usage

Insert following code into view

<?php $this->widget('path.to.multicomplete.MultiComplete', array(
          'model'=>$model,
          'attribute'=>'news_tags',
          'splitter'=>',',
          //'source'=>array('ac1', 'ac2', 'ac3'),
          'sourceUrl'=>'search.html',
          // additional javascript options for the autocomplete plugin
          'options'=>array(
                  'minLength'=>'2',
          ),
          'htmlOptions'=>array(
                  'size'=>'60'
          ),
  ));
  ?>

if you want to use static source - you must use source Option, if you want to get tags dynamically you must specify sourceUrl option, and use the following code in controller:

public function actionSearch()
     { //completion variants
      echo '[ 
       "ActionScript",
       "AppleScript",
       "Asp",
       "BASIC",
       "C",
       "C++",
       "Clojure",
       "COBOL",
       "ColdFusion",
       "Erlang",
       "Fortran",
       "Groovy",
       "Haskell",
       "Java",
       "JavaScript",
       "Lisp",
       "Perl",
       "PHP",
       "Python",
       "Ruby",
       "Scala",
       "Scheme"
      ]';
     }

How to get tags from a model

public function actionSearch($term)
     {
          if(Yii::app()->request->isAjaxRequest && !empty($term))
        {
              $variants = array();
              $criteria = new CDbCriteria;
              $criteria->select='tag';
              $criteria->addSearchCondition('tag',$term.'%',false);
              $tags = tagsModel::model()->findAll($criteria);
              if(!empty($tags))
              {
                foreach($tags as $tag)
                {
                    $variants[] = $tag->attributes['tag'];
                }
              }
              echo CJSON::encode($variants);
        }
        else
            throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
     }

Additional options

splitter(string) - tag splitter to parse tag input string

Screenshot

Multicomplete screenshot

Resources

Total 5 comments

#16046 report it
CrazyCat at 2014/01/14 10:32am
What about many_many relations ?

Hello there,

I want to use this extension with a many_many relation, but it doesn't work because my field contains an array of objects and not a string value.

Peharps have I to add a small hack to check the attribute type and transform it in a comma separated string if it's an array ?

#12217 report it
samilo at 2013/03/07 07:38am
suggestion to devlope in future

Hi thank u . I suggest to develop it related to Gridview filter , Then will be perfect ext .

#7759 report it
lvil at 2012/04/16 03:30am
Thank you

1 minute implementation, simple usage, great extension. Thank you!

#5940 report it
szako at 2011/11/27 01:52pm
Hey

Thanks, that's what I needed!

#2279 report it
robregonm at 2010/12/06 09:22am
Great

Excellent idea. I'll give it a try... ;)

Leave a comment

Please to leave your comment.

Create extension