Yii2: Attributes for dropDownList prompt

Created on 24 Feb 2015  路  2Comments  路  Source: yiisoft/yii2

It's possible to add attributes to a dropDownList's option tags using the 'options' element in $options, e.g.:

$form->field($model, 'foo')->dropDownList(['value1' => 'One', 'value2' => 'Two'], [
    'options' => [
        'value1' => ['disabled' => true],
        'value2' => ['class' => 'bar']
    ],
    'prompt' => 'please choose',
])

But it's not possible to add attributes to the option tag generated by 'prompt'. I'd like to do this:

$form->field($model, 'foo')->dropDownList(['value1' => 'One', 'value2' => 'Two'], [
    'prompt' => 'please choose',
    'promptOptions' => [
        'class' => 'drop-down-prompt'
    ]
])
ready for adoption enhancement

Most helpful comment

How about this syntax?

'prompt' => ['label' => 'Please Choose', 'class' => 'drop-down-prompt', 'value' => '-1'];

completely backwards compatible and won't add any new variables

All 2 comments

How about this syntax?

'prompt' => ['label' => 'Please Choose', 'class' => 'drop-down-prompt', 'value' => '-1'];

completely backwards compatible and won't add any new variables

@Faryshta, you seem to be right on this. How about a PR?

Was this page helpful?
0 / 5 - 0 ratings