soless/yii2-jquery-tageditor-widget

Widget for a powerful and lightweight tag editor plugin for jQuery with available tags select buttons

1.0.6 2018-02-18 07:13 UTC

This package is auto-updated.

Last update: 2024-03-29 03:38:29 UTC


README

Widget for tags adding. Based on https://goodies.pixabay.com/jquery/tag-editor/demo.html

Installation The preferred way to install this extension is through composer.

composer require --prefer-dist soless/yii2-jquery-tageditor-widget "*"

usage:

  <?php echo $form->field($model, 'selectedTags')->widget('soless\tageditor\TagEditorWidget', [
	'availableTags' => ['firstTag', 'secondTag', 'thirdTag', ],
        'tagEditorOptions' => [
            'forceLowercase' => false,
            'autocomplete' => [
                'source' => \yii\helpers\Url::toRoute(['/tag/suggest'])
            ],
        ]
    ]) ?>

app\controllers\TagController (suggest action example) :

   public function actionSuggest($term) {
  Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

      return \yii\helpers\ArrayHelper::getColumn(
      \common\models\Tag::find()
      ->select('title')
      ->filterWhere(['like', 'title', $term.'%', false])
      ->all(), 
      'title'
  );
  }