P
P
prosperodesu2016-11-16 00:44:50
Yii
prosperodesu, 2016-11-16 00:44:50

PHP Yii2 select2 widget from kartik, when you try to delete or change one tag, everything is deleted, what's wrong?

There is a select2 widget for yii2 from kartik-v with the multiple:true option enabled, everything works fine except for one thing, when initializing the initial values ​​​​for the field and then trying to edit these values, remove one tag or add one tag to the input, or remove all tags in input , or all tags are replaced with the new value.
The code:

<?php
            /* init data */
            $init = null;
            if (array_key_exists($tag->id, $keywordOnTag)) {
                $init = implode(',', $keywordOnTag[$tag->id]);
            }
            echo Editable::widget([
                'name' => 'tags_keywords',
                'format' => 'button',
                'editableButtonOptions' => ['style' => 'color:black;'],
                'inputType' => Editable::INPUT_SELECT2,
                'value' => $tag->name,
                'header' => 'ключевые слова',
                'size' => 'md',
                'placement' => 'top',
                'formOptions' => ['action' => '/ajax/api/tags/link/keywords?id=' . $tag->id],
                'options' => [
                    'name' => 'tags',
                    'value' => [2],
                    'attribute' => 'name',
                    //'data' => ArrayHelper::map($keywords, 'id', 'name'),
                    'options' => [
                        'multiple' => true,
                        'tokenSeparators' => [',', " ", ', '],
                    ],
                    'pluginOptions' => ['initSelection' => new JsExpression("function (element, callback)
                        {
                            var data = [$init];
                            callback(data);
                        }"),
                        'ajax' => ['url' => '/ajax/api/keywords/list', 'dataType' => 'json'],
                        'language' => [
                            'errorLoading' => new JsExpression("function () { return 'Загрузка кэйвордов...';}"),
                        ],
                    ]
                ]
            ]);

            ?>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question