Issues With Dropdownlist Selected Attribute

Hi Everyone :)

i’m having issues with the dropDownList, when i want to set the “selected” attribute for an option tag.

In my Code bellow, this is how i setup the dropdownlist and set the ‘selected’ attribute to true.

The issue i have is, it doesn’t select the item unless i have a trailing or leading whitespace before or after selected.

The behaviour is just for ‘selected’, if i put ‘disabled’, ‘class’, ‘myfunnyattribute’ i renders fine or gets at least displayed in the source code.

any thoughts? not shure why it won’t work without the whitespace, many thanks everyone :)

Inside the View:


$form->field($model, $key, 

                        ['options' => 


                                'class' => 'col-xs-3'





                        ['options' =>


                                $user->$key => ['selected ' => true]




Function in Model:

public function getTeamname()


    $team = Team::find()->orderBy('teamName')->all();

    return ArrayHelper::map($team, 'teamID', 'teamName');


Does it work if you try,

['selected' => 'selected']

No doesn’t work either

$user->$key => ['selected' => 'selected']

Renders to:

<option value="9">

    IT Administration


However, again with trailing whitespace it works

$user->$key => ['selected ' => 'selected']

Which renders to:

<option selected="selected" value="9">

    IT Administration


Tried it with Firefox 27.0.1 and IE 11.0.3