Ich versuche, Select2 zu verwenden und in einem dynamischen Formular abzulegen. Für die erste Reihe funktioniert es nur. Aber in der nächsten Zeile bekomme ich folgenden Fehler. Select2 und DepDrop in dynamischer Form in yii2
Wenn ich select2 ohne depfrop verwende, funktioniert es gut.
Code of Form (von select2 und depdrop Feld)
<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 of 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 lassen Sie mich wissen, wenn mehr Input von meinem Ende erforderlich ist.