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
Great
Excellent idea. I'll give it a try... ;)
Hey
Thanks, that's what I needed!
Thank you
1 minute implementation, simple usage, great extension.
Thank you!
suggestion to devlope in future
Hi thank u .
I suggest to develop it related to Gridview filter , Then will be perfect ext .
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 ?
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.