Yii1 Get options selected in dropdown when options has extra atrributes

321 Views Asked by At

When i add extra atrribute to options in CHtml::dropDownList(), i am not able to set options selected.

Without adding extra atrribute to CHtml::dropDownList(), i am able to get an option selected and the code for this is

echo CHtml::dropDownList("rating[$i]", '', CHtml::listData(Rating::model()->findAll($criteria), 'id', 'Description'), array('prompt' => 'Select a rating', 'options' => array($question->rating_id => array('selected' => TRUE)), 'class' => 'input-xlarge ddc hrq'));

But when i add extra atrribute, selected option not work, modified code is

 echo CHtml::dropDownList("rating[$i]", '', CHtml::listData(Rating::model()->findAll($criteria), 'id', 'Description'), array('prompt' => 'Select a rating', 'options' => array($question->rating_id => array('selected' => TRUE), '1' => array('number' => 5), '2' => array('number' => 4), '3' => array('number' => 3), '4' => array('number' => 2), '5' => array('number' => 1), '16' => array('number' => 0)), 'class' => 'input-xlarge ddc hrq'));

Please help me with this. Thanks in advance :)

0

There are 0 best solutions below