Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

370
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!