0

It is necessary to pre-select the values in the dropdown. But for some reason, the values do not predispose. How to fix it?

All items - $items:

array(1) {
  [1]=>
  string(29) "Санкт-Петербург"
}

$selectedItems:

array(1) {
  [1]=>
  string(29) "Санкт-Петербург"
}  

<?= Html::dropDownList('cities', $selectedItems, $items, ['class' => 'form-control', 'multiple' => true]) ?>
rob006
  • 21,383
  • 5
  • 53
  • 74
kome
  • 51
  • 1
  • 2
  • 5

1 Answers1

2

$selectedItem should contain only selected indexes.

For example:

$items[0] = 'A'; // preselected
$items[1] = 'B';
$items[2] = 'C'; // preselected

$selectedItems = [0, 2];

echo Html::dropDownList('cities', $selectedItems, $items, ['class' => 'form-control', 'multiple' => true]);
rob006
  • 21,383
  • 5
  • 53
  • 74
Tomash
  • 36
  • 3