i have a dropdown here in yii that looks like this:
<?php echo $form->dropDownList($model, 'is_enabled',
array('0'=>'No', '1'=>'Yes'), array('id'=>'new-sys-user-is_enabled',));?>
the problem with this is that it shows the 'No' because it has the 0 key. I would like to show the 'Yes' by default. What is the work-around for this?
asked Jan 7, 2014 at 1:20
Eric Santos
2031 gold badge2 silver badges11 bronze badges
2 Answers 2
Check out if this works for you: http://www.yiiframework.com/forum/index.php/topic/11748-dropdownlist-selected-option/
EDIT: Copying the relevant part:
$form->dropDownList($model,'sex',array('1'=>'men','2'=>'women'), array('options' => array('2'=>array('selected'=>true))));
answered Jan 7, 2014 at 1:23
GabrielF
2,1311 gold badge18 silver badges33 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Bud Damyanov
This should be accepted answer
I think you should try like this ...
<?php echo $form->dropDownList($model, 'is_enabled', array('1'=>'Yes', '0'=>'No'), array('id'=>'new-sys-user-is_enabled',));?>
The value you want to keep default value, then keep first in array too.
Thanks
answered Jan 7, 2014 at 4:49
Muhammad Rizwan Kaim Khani
2,1003 gold badges30 silver badges39 bronze badges
Comments
lang-php