Select2 und DepDrop in dynamischer Form in yii2

Ich versuche, Select2 zu verwenden und in einem dynamischen Formular abzulegen. In der ersten Reihe funktioniert es nur. Aber in der nächsten Zeile erhalte ich folgende Fehlermeldung.

Wenn ich select2 ohne depfrop verwende, funktioniert es einwandfrei.

Code des Formulars (von select2 und depdrop field)

<div class="col-xs-3 col-sm-3 col-lg-3">

                                    <?= $form->field($modelsProductsales, "[{$i}]productname")->label(false)->widget(Select2::classname(), [
                                    'data' => ArrayHelper::map(Productbatch::find()->orderBy('productname')->all(),'productname','productname'),
                                    'language' => 'en',
                                    'options' => ['placeholder' => 'Select Product','id' => 'prodname'],
                                    'pluginOptions' => [
                                        'allowClear' => true
                                    ],
                                    ]); 
                                ?>                                  
                                </div>
                                <div class="col-xs-1 col-sm-1 col-lg-1 nopadding">   
                                    <?= $form->field($modelsProductsales, 'batchno')->label(false)->widget(DepDrop::classname(), [
                                    //'options'=>['id'=>'subcat-id'],
                                    'pluginOptions'=>[
                                        'depends'=>['prodname'],
                                        'placeholder'=>'Batch No',
                                        'url'=>Url::to(['/invoice/bills/subcat'])
                                    ]
                                    ]); ?>

Code der Subcat-Aktion

public function actionSubcat() {
    $out = [];
    if (isset($_POST['depdrop_parents'])) {
        $parents = $_POST['depdrop_parents'];
        if ($parents != null) {
            $cat_id = $parents[0];
            $out = Productbatch::getBatchNo($cat_id);
            echo Json::encode($out);
            // the getSubCatList function will query the database based on the
            // cat_id and return an array like below:
            // [
            //    ['id'=>'<sub-cat-id-1>', 'name'=>'<sub-cat-name1>'],
            //    ['id'=>'<sub-cat_id_2>', 'name'=>'<sub-cat-name2>']
            // ]
            //echo Json::encode(['output'=>$out, 'selected'=>'']);
            return;
        }
    }

Bitte teilen Sie mir mit, ob weitere Eingaben von meiner Seite erforderlich sind.

Antworten auf die Frage(2)

Ihre Antwort auf die Frage