2

Can you format the style of the DropDownList in yii2 I have the following code that generates a list from a table and I wanted to change the text size and color of the items to choose from.

    <div class="form-group search-form">
    <?php 
    echo $form->field($model, 'spec')
    ->dropDownList(
        $specialities,    
        ['prompt'=>'Any Speciality']
    )->label('');
    ?>
    </div><!--end of form-group-->
samauto
  • 137
  • 2
  • 15

1 Answers1

2

should be the options

<div class="form-group search-form">
<?php 
      echo $form->field($model, 'spec')
      ->dropDownList(
            $specialities,    
            ['prompt'=>'Any Speciality', 
            'options' => ['style' => 'color: #FA4577; font-size: 18px;'],]
       )->label('');
?>
</div><!--end of form-group-->
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
  • It's not working for me - of course it doesn't mean that this is not the right answer. – user2511599 Aug 17 '18 at 09:20
  • 2
    For me it's working this way: `['prompt' => Yii::t('yii', 'Select'), 'style' => 'color: red; font-size: 18px;',]` so without `options`. – user2511599 Aug 17 '18 at 09:23
  • @user2511599 . you should post a new question with your code .. and describe your need and your specific problems ... eventually comment me the link – ScaisEdge Aug 17 '18 at 09:23
  • you code is not enough .. or if you thinks of have found a valid solution you can add your code as a new answer .. – ScaisEdge Aug 17 '18 at 09:24
  • `= $form->field($model, 'zwzx_id')->dropDownList( ZwzX::find()->getBiggerActiveAsArray($a->fn, $a->zn, $a->z, $a->drz, $a->p), [ 'prompt' => Yii::t('yii', 'Select'), 'style' => 'color: red; font-size: 18px;', ]); ?>` I think it's basically quite the same. – user2511599 Aug 17 '18 at 09:26
  • I don't think my answer is better, I just have no clue why it's not working for me, when it was obviously working for @samauto Changes in framework maybe...? – user2511599 Aug 17 '18 at 09:29
  • take a look at ref for check .. (seems correct to me) anyway seem there are some change with yii 2.0.11 .. https://www.yiiframework.com/doc/api/2.0/yii-helpers-basehtml#activeDropDownList()-detail – ScaisEdge Aug 17 '18 at 09:34
  • Yeah, seems correct. Pretty strange. However, sometimes documentation is also not 100% perfect. – user2511599 Aug 17 '18 at 09:37
  • in the code i'm use i have some of this object and works correcly .. . – ScaisEdge Aug 17 '18 at 09:43
  • I have Yii 2.0.15.1 what do you have? – user2511599 Aug 17 '18 at 09:45
  • @user2511599 actually i'm on 2.0.14.1 – ScaisEdge Aug 17 '18 at 09:46
  • I don't think that makes any difference, but I have no clue – user2511599 Aug 17 '18 at 09:49