Vitaly Park
Vitaly Park

Reputation: 57

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.

Upvotes: 0

Views: 2602

Answers (2)

rakhmatov
rakhmatov

Reputation: 377

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
        ],
    ]); 

Upvotes: 0

rakhmatov
rakhmatov

Reputation: 377

just use a listbox

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

or use a select2 widget by kartik

Upvotes: 1

Related Questions