A
A
AlexAll2019-03-03 18:39:50
Yii
AlexAll, 2019-03-03 18:39:50

How to correctly insert \kartik\select2\Select2 plugin into unclead\multipleinput\MultipleInput plugin in yii2?

Trying to embed \kartik\select2\Select2 plugin into unclead\multipleinput\MultipleInput
Here is instruction from MultipleInput
Here is embed code

<?php

        echo $form->field($model, 'items')->widget(MultipleInput::className(), [

            'columns' => [
                [
                    'name' => 'slide',
                    'type' => \kartik\select2\Select2::className(),
                    'options' => [
                        'options' => ['placeholder' => 'Поиск  ...'],
//                       'initValueText' => empty($model->items) ? '' : Item::findOne($model->items)->title,
                       'pluginOptions' => [   
                            'allowClear' => true,
                            'minimumInputLength' => 3,
                            'language' => 'ru',
                            'ajax' => [
                                'url' => \yii\helpers\Url::to(['item-list']),
                                'dataType' => 'json',
                                'data' => new JsExpression('function(params) { return {q:params.term}; }')
                            ],
                            'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
                            'templateResult' => new JsExpression('function(item_id) { return item_id.text; }'),
                            'templateSelection' => new JsExpression('function (item_id) { return item_id.text; }'),
                        ],
                    ],
                ],
      
            ]
        ])->label(false);
        ?>

1) For some reason it saves empty values
​​2) After saving, it does not show the saved fields
Made for this in the model
public $items;
    public function init()
    {
        parent::init();

        $title = [];
        foreach ($this->itemall as $item){

           $title[]['slide'] =  empty($item['item_id']) ? '' : Item::findOne($item['item_id'])->title;
 
        }

        $this->items = $title;

    }

    public function getItemAll()
    {
        return self::find()->orderBy(['id' => SORT_ASC])->asArray()->all();
    }

And it seems to work, but it’s disabled, since the FIRST problem still remains (it saves empty fields)
And the second one, I get an array from id in the database and in the public function init() in the model I look for names by them and then I pass the array to public $items
A I would like to pass an array of shnikov id to the widget form itself so that it accepts id and searches for the title itself here
'initValueText' => empty($model->items) ? '' : Item::findOne($model->items)->title,

But nothing comes out because $model->items contains an array
. What do you recommend?

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