I would like to disable the first option from a dropdownlist using yii2 framework. The first option is the prompt one.
<?php echo $form->field($kind, 'cod_kind')
->label($kind->attributeLabels() ['cod_kind'] . " (*)")
->dropDownList($kind, ['prompt' => 'Select', 'id' => 'cod_kind']);
Already tried to do something like this but it did not work, got error exception:
->dropDownList($kind, ['prompt' => ['label' => 'Select', 'disabled' => true], 'id' => 'cod_kind']);
My question is different from this question because I don't want to disable an available option. I want to disable the prompt option, the option that has the label 'Select'. One more time, already tried the solution of that question with the prompt option and it gave me an error exception.
<?= $form->field($model, 'class', ['template' => '{input}'])->dropDownList(\yii\helpers\ArrayHelper::map($classifiler->find()->all(), 'id', 'name'), ['class' => 'input-custom input-full', 'required' => true,
'prompt' => [
'text' => 'Select',
'options'=> ['disabled' => true, 'selected' => true]
]])->label(false); ?>
You need to set up the required validator:
['cod_kind', required]
That's it. On an attempt to choose the prompt option the user will get an error message.