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'
]
])
->dropDownList(
$model->getTeamName(),
['options' =>
[
$user->$key => ['selected ' => true]
]
]
);
Function in Model:
public function getTeamname()
{
$team = Team::find()->orderBy('teamName')->all();
return ArrayHelper::map($team, 'teamID', 'teamName');
}