Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a placeholder to a dropdown in Yii2?

Tags:

yii2

I need to add a placeholder into my dropdown and somehow it doesn't work.

Here is my input field:

<?= $form->field($category, 'id')->dropDownList($categoryList, [
    'id' => 'category-id',
    'prompt' => 'Select category', [
        'disabled' => true,
       ]
]); ?>

Could someone explain me what I'm doing wrong? Thanks for any help!

like image 784
HELPME Avatar asked May 10 '17 10:05

HELPME


1 Answers

DropDownList has no placeholder, use 'prompt' instead:

$form->field($category, 'id')->dropDownList($categoryList, [
    'id' => 'category-id',
    'prompt'=>'- Select category -'
]);
like image 152
gmc Avatar answered Nov 01 '22 10:11

gmc