Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

371
Vistas
Disable Prompt Option Dropdownlist in Yii2

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.

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

<?= $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); ?>
about 4 years ago · Santiago Trujillo Denunciar

0

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.

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda