S
S
Sergey Suntsev2017-03-18 13:39:30
Yii
Sergey Suntsev, 2017-03-18 13:39:30

How to design array for active form with multiple choice?

There is a model that contains the following data: site number (id), cost with equipment (value), cost without equipment (w_e_value) and the user ID to which the site is assigned (user_id).
It is necessary in some way (preferably) through the active form to implement the display of sites for selection.
It seems to have implemented the conclusion, but the choice is possible only one site.
How to correctly form an array so that it is possible to select several sites at the same time?
170eef55ec274557b2eeed5c4d4688cf.JPG

<? foreach ($standsModel as $stand):  
 $items[$stand->stand] = ['Площадь - '.$stand->area_space.' кв.м. Стоимость - '.$stand->value_equipped_playground.'р. Стоимость без оборудованния - '.$stand->value_not_equipped_playground.'р.'];
        endforeach; 
        $params = [
            'prompt' => 'Выберите стенд',
            'multiple' => 'true'
        ];
        echo $form->field($model, 'number_area_stand')->dropDownList($items, $params);
        ?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Fedorov, 2017-03-19
@GreyCrew

$form->field($model, 'number_area_stand')->dropDownList($items, ['multiple' => true]);

will allow you to select multiple records (with the Ctrl key pressed). Do not also forget that if you allow a choice of multiple values ​​for the number_area_stand attribute in the form, it must be an array in the model.
In general, if there is a task of multiple selection, I would recommend not to use the standard dropDownList. Instead, it is better to use specialized widgets, such as Select2 . This will make the resource more user-friendly.

A
Abdula Magomedov, 2017-03-18
@Avarskiy

Like so

echo $form->field($model, 'number_area_stand[]')->dropDownList($items, $params);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question