appage / yii2-taggle
Yii2 Widget for okcoker/taggle.js
This package's canonical repository appears to be gone and the package has been frozen as a result.
v0.8.4
2017-09-08 16:35 UTC
Requires
- bower-asset/taggle: ^1.11
- yiisoft/yii2: *
README
Yii2 Widget for okcoker/taggle.js
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist appage/yii2-taggle "*"
or add
"appage/yii2-taggle": "*"
to the require section of your composer.json
file.
Usage
Once the extension is installed, simply use it in your code by :
<?= \appage\taggle\widgets\TagsWidget::widget([
'clientOptions' => [
'tags' => ['These', 'are', 'prefilled', 'tags'],
],
'name' => 'example[]',
]) ?>
or with model: (add two blocks together)
// If tags list empty, this will save empty array
<?= $form->field($model, 'tagsList')->hiddenInput([
'name' => $model->formName() . '[tagsList][]',
'value' => '',
])->label(false) ?>
// If not empty - this will add tags
<?= $form->field($model, 'tagsList[]')->widget(\appage\taggle\widgets\TagsWidget::className(), [
'clientOptions' => [
'hiddenInputName' => $model->formName() . '[tagsList][]',
'tags' => ($model->tagsList ? $model->tagsList : []),
],
]) ?>
If you store tags list like a string with comma separator you can use our behavior for model:
public function behaviors()
{
return [
'tagsList' => [
'class' => 'appage\taggle\behaviors\TagsBehavior',
'owner' => $this,
],
];
}
And add safe rule for tagsList
Note: don't forget to add $hiddenInputName param
To show tags you can use TagsListWidget:
echo TagsListWidget::widget([
'tagsList' => $model->tagsList,
]);
For more info you can see okcoker/taggle.js documentation.