2amigos / yii2-multi-select-widget

Bootstrap MultiSelect and MultiSelect Listbox widgets for Yii2
https://2amigos.us
Other
45 stars 29 forks source link

Multiple preselected with model #4

Closed agaplus closed 7 years ago

agaplus commented 9 years ago

Preselect with 'model' and 'attribute' instead of 'name' and 'value'' works if the preselect is only one. Or maybe i not pass a valid data...

echo MultiSelect::widget([
                    "options" => ['multiple'=>"multiple"], // for the actual multiselect
                    'data' =>  $listData,
                    'model' => $model,
                    'attribute' => "centro_id",
                    "clientOptions" =>
                        [
                            "includeSelectAllOption" => false,
                            'numberDisplayed' => 3,
                        ],
                ]);

how can I do?

tonydspaniard commented 9 years ago

Whats $listData?

agaplus commented 9 years ago

$centri = Centro::find()->all(); $listDatai=ArrayHelper::map($centri,'id','nome');

tonydspaniard commented 9 years ago

I have to refactor this application for the new http://yiiwheels.com site. Will handle this issue when doing it.

Thanks.

tonydspaniard commented 9 years ago

Nevertheless, how are you going to preselect multiple? Is the attribute an array? have you seen this: https://github.com/2amigos/yii2-multi-select-widget/issues/1#issuecomment-47092009