Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

372
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda