1

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

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

This should be accepted answer
0

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

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.