yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.24k stars 6.91k forks source link

Generate dropDownList from a boolean field in a model #11962

Closed bernhar closed 8 years ago

bernhar commented 8 years ago

I have a form. In this form I want to show a dropDownList (instead of a checkbox), as I want to know if it is blank (null), or answered (true or false). Using the following code will always bring me the PROMPT option when FALSE.

<?= $form
    ->field($model, 'bln_choice')
    ->dropDownList(['1' => 'Yeah!', '0' => 'Nope!'],['prompt'=>'Chose, dude!'])
?>

Is there a way to do so in a native fashion? Thanks

yii-bot commented 8 years ago

This is an automated comment, triggered by adding the label question.

Please note, that the GitHub Issue Tracker is for bug reports and feature requests only.

We are happy to help you on the support forum, on IRC (#yii on freenode), or Gitter.

Please use one of the above mentioned resources to discuss the problem. If the result of the discussion turns out that there really is a bug in the framework, feel free to come back and provide information on how to reproduce the issue. This issue will be closed for now.

sokollondon commented 4 years ago

Same problem. It helped:

echo Html::activeLabel($model, 'is_active');
echo Html::dropDownList('Post[is_active]', 
    ($model->is_active===false ? '0' : $model->is_active),
    [false=>'No', true=>'Yes'], ['class'=>'form-control']);