Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii: How to add CSS class to a dropdown list

Tags:

php

yii

I am using Yii 1.1.10. I would like to know how to add a CSS class to a dropdown list. I am using a CActiveForm

for example, how would i add a CSS class to this dropdown list?

<?php echo $form->labelEx($model,'chassis'); ?>
<?php echo $form->dropDownList($model, 'chassis',
      array('saloon' => 'saloon', 'station wagon' => 'station wagon', ),
   ); 
?>

EDIT: I had this in my code

 array('empty' => 'Select one of the following...')

i had it there to make it the default message. but somehow it interfered with using

'htmlOptions'=>array('class'=>'yourCssClass')

OR

array('class'=>'your_class_name')

so as long as i remove it, both suggestions work!Thank guys

like image 678
Victor Njoroge Avatar asked Jan 22 '26 16:01

Victor Njoroge


1 Answers

You can use htmlOptions argument of CActiveFrom::dropDownList() to specify class,style or any other HTML attributes.

<?php echo $form->labelEx($model,'chassis'); ?>
<?php echo $form->dropDownList($model, 'chassis',
      array('saloon' => 'saloon', 'station wagon' => 'station wagon', ),
      array('class'=>'your_class_name'),
   ); 
?>
like image 123
dInGd0nG Avatar answered Jan 25 '26 06:01

dInGd0nG



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!