A
A
Alexander Verbitsky2019-02-08 05:05:39
Yii
Alexander Verbitsky, 2019-02-08 05:05:39

How to set default values ​​in select2 when editing?

I have a select with 'multiple' => true
There are no problems with saving the data. But when I click on edit, in theory there should be saved data in this field (because this is multiple, then there are several data)
How to make them appear when you enter editing ???

echo $form->field($contractObjects, 'contract_objects_object_id')->widget(
                Select2::classname(), [
                                        'hideSearch'    => false,
                                        // 'initValueText' => '',
                                        // 'value' => '',
                                        'options'       => [
                                            'class'       => 'select-category',
                                            'placeholder' => 'Выберите объект',
                                            'multiple' => true
                                        ],
                                        'theme'         => Select2::THEME_DEFAULT,
                                        'data' => ['первое значение', 'второе значение', 'третье значение']
                                    ]
            );

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2019-02-08
@webinar

uncomment value and pass an array of keys (if my memory serves me)
'value' => [0,2]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question