forked from sjaakp/yii2-taggable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TagEditor.php
45 lines (36 loc) · 1.07 KB
/
TagEditor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
/**
* MIT licence
* Version 1.0
* Sjaak Priester, Amsterdam 13-05-2015.
*
* Input widget for Yii 2.0
*
* Widget to enter, delete and interactively sort tags.
*
* Uses jQuery tagEditor.
* @link http://goodies.pixabay.com/jquery/tag-editor/demo.html
*
*/
namespace sjaakp\taggable;
use yii\widgets\InputWidget;
use yii\helpers\Html;
use yii\helpers\Json;
class TagEditor extends InputWidget {
/**
* @var array
* The Javascript options of the jQuery tagEditor widget.
*/
public $tagEditorOptions = [];
public function run() {
$view = $this->getView();
$asset = new TagEditorAsset();
$asset->register($view);
$id = $this->getId();
$this->options['id'] = $id;
$teOpts = count($this->tagEditorOptions) ? Json::encode($this->tagEditorOptions) : '';
$view->registerJs("jQuery('#$id').tagEditor($teOpts);");
return $this->hasModel() ? Html::activeTextInput($this->model, $this->attribute, $this->options)
: Html::textInput($this->name, $this->value, $this->options);
}
}