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

  1. Requirements
  2. Usage
  3. How to get tags from a model
  4. Additional options
  5. Screenshot
  6. Resources

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

15 0
20 followers
1 981 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: User Interface
Developed by: GOsha
Created on: Dec 5, 2010
Last updated: 5 years ago

Downloads

show all

Related Extensions