Disable option list in Yii2
I would like to disable the first option from the dropdown using yii2 framework. The first option is a hint.
<?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 didn't work, it got an 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 turn off the hint option that has the label Select. Once again, already tried the solution to this question with the prompt option and it gave me an error.
+3
Danielson silva
source
to share
2 answers
You need to set up a validator required
:
['cod_kind', required]
What is it. When trying to select the prompt option, the user will receive an error message.
0
Sergey Okatov
source
to share
<?= $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); ?>
0
mat.twg
source
to share