Skip to content
Advertisement

Yii: How to add inline style to select option item?

I have select HTML tag generated by this code:

<?= $form->field($model, 'something')->dropDownList(Class::method(), 
  ['prompt' => Yii::t('app', '--- Choose ---')]) ?>

I would need to add an HTML attribute (e.g. inline style) to each option tag.

Can you give me a hint, please?

Advertisement

Answer

You can use options

  <?= $form->field($model, 'something')->dropDownList(Class::method(), 
   ['prompt' => Yii::t('app', '--- Choose ---'), 
     'options' => ['value1' => ['style' => 'color:red;'],]]) ?>
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement