简体   繁体   中英

Dropdown List multiselection in yii2

I need multiselection in dropdown list. This my dropdown list

<?= $form->field($model, 'receiver_id')->dropDownList(
    ArrayHelper::map(User::find()->all(),'id','username'),
    ['prompt' => 'Select receiver...']
) ?>

But it's only for one receiver. I want to choose some receivers and display them in textfield of this list separated by commas. Could you help with this problem? Thank you in advance for any help you can provide.

just use a listbox

<?= $form->field($model, 'receiver_id')->listbox(
    ArrayHelper::map(User::find()->all(),'id','username')
) ?>

or use a select2 widget by kartik

use like this

    echo $form->field($model, 'state_1')->widget(Select2::classname(), [
        'data' => $data,
        'options' => ['placeholder' => 'Select a color ...', 'multiple' => true],
        'pluginOptions' => [
            'tags' => true,
            'maximumInputLength' => 10
        ],
    ]); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM