Multiple sample with a drop list select2



  • Hello, comrades.

    The problem is, I'm trying to make a multiple sample of the recipients of the letter by using the rolling list kartik select2:

    <?= $form->field($model, 'receiver_id')->widget(Select2::classname(),
        [ 'data' => ArrayHelper::map(User::find()->all(),'id','username'),
            'options' =>
                ['placeholder' => 'Select receivers...', 'multiple' => true],
            'pluginOptions' =>
                [ 'tags' => true,
                    'maximumInputLength' => 10
                ],
        ]);
    ?>
    

    But when the Send button is pressed under the textbook of Receiver ID, the red mistake of Receiver ID must be an integer.

    Please explain how to use this list correctly or provide alternative solutions.

    Thank you.



  • Like a mistake. You've got an idiosyncrist.

    <?= $form->field($model, 'receiverIDs')->widget(Select2::classname(), [
            'data' => ArrayHelper::map(User::find()->all(),'id','username'),
            'options' => [
                'placeholder' => 'Select receivers...', 
                'multiple' => true,
            ],
            'pluginOptions' => [ 
                'tags' => true,
                'maximumInputLength' => 10,
            ],
        ]);
    ?>
    

    And in the fashion

    class Model extends base\ActiveRecord {
    
    public function rules() {
        return [
            //....
            ['receiverIDs', 'each', 'rule' =&gt; ['integer']]
        ];
    }
    
    public $receiverIDs = [];
    

    }

    I don't remember how Select2 keeps these structures. Or in a comma like a line, then you have to. explode(',' , $this->receiverIDs) Or as an idyshine. Look what's in the request.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2