php - Yii2 dropdown optgroup label
Get the solution ↓↓↓Solution:
Remove extra[]
<?= $form->field($model, 'idcmp_usr')->dropDownList(Company::find()
->select(['name_cmp','id_cmp'])
->indexBy('id_cmp')
->column()
); ?>
Answer
Solution:
Here, Solution to Map Parent and Chind Lable Group in Yii2, optgroup label
$data = Array
(
[Group1] => Array
(
[5] => Group1 Apartment
[6] => Group1Apartment
[7] => Group1
[8] => Group1House
[9] => Group1 Plot
[10] => Group1 House
[11] => Group1 Apartment
[12] => Group1 House
)
[Group2] => Array
(
[13] => Group2 Office
[14] => Group2 IT Park/SEZ
[15] => Group2 Shop
[16] => Group2 Show Room
[17] => Group2 Land
[18] => Group2 GoDown
)
[Group3] => Array
(
[19] => Group3 Land
[20] => Group3 Shed
)
[Group4] => Array
(
[22] => Group4 Land
)
)
Form---
<?= $form->field($model, 'group_type')->dropDownList($data, ['disabled' => (!$model->isNewRecord) ? true : false, 'prompt' => 'Select', 'options' => [$model->isNewRecord ? '' : $model->group_type->parent_id => ["Selected" => true]]])?>
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: script cache:clear returned with error code 255
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.