Hi,
I’m facing issue in kartik drepdrop (select2 type) keeps loading in dynamic form second element or more.
I looked into browser console and there was no any errors.
I’m using hosannahighertech/yii2-dynamicform": "^1.0
I have used kartik/select2 in this dynamic form and it is OK, but now the problem is in kartik dredrop select2 type.
please advice. thanks before.
I noticed that when i changed the first selected item, both or more warehouse fields would follow the value of first warehouse. here the exampe
This is my form.
<div class="item-usage-form">
<?php $form = ActiveForm::begin(['id' => 'form-item-usage']); ?>
<?php DynamicFormWidget::begin([
'widgetContainer' => 'dynamicform_wrapper', // required: only alphanumeric characters plus "_" [A-Za-z0-9_]
'widgetBody' => '.container-items', // required: css class selector
'widgetItem' => '.item', // required: css class
'limit' => 12 , // the maximum times, an element can be cloned (default 999)
'min' => 1, // 0 or 1 (default 1)
'insertButton' => '.add-item', // css class
'deleteButton' => '.remove-item', // css class
'model' => $details[0],
'formId' => 'form-item-usage',
'formFields' => [
'item_id',
'qty',
'warehouse_id',
'disc_percent',
'hpp'
],
]); ?>
<div class="card">
<div class="card-header">
<span><i class="fa fa-cart-plus"></i></span>
<span style="font-size: large;"> Items Sparepart</span>
<button type="button" class="float-right add-item btn btn-success btn-sm">
<i class="fa fa-plus"></i> Add item</button>
<div class="clearfix"></div>
</div>
<div class="card-body container-items"> <!-- widgetContainer -->
<?php foreach ($details as $i => $detail): ?>
<div class="item card"> <!-- widgetBody -->
<div class="card-header">
<?php
// necessary for update action.
if (! $detail->isNewRecord) {
echo Html::activeHiddenInput($detail, "[{$i}]id");
}
?>
<span class="card-item-title" style="color: blue;">Item : <?= ($i+1) ?></span>
<button type="button" class="float-right remove-item btn btn-danger btn-sm">
<i class="fa fa-minus"></i></button>
<div class="clearfix"></div>
</div> <!-- card-header -->
<div class="card-body">
<div class="row">
<div class="col-4">
<?= $form->field($detail, "[{$i}]item_id")->widget(Select2::class, [
'data' => ArrayHelper::map(\app\models\ItemSparepart::find()->where(['listed' => 1])->all(), 'id', 'name'),
'language' => 'en',
'options' => [
'placeholder' => 'Select item ...',
],
'pluginOptions' => [
'allowClear' => true,
],
]);
?>
<?php
// Additional input fields passed as params to the child dropdown's pluginOptions
echo Html::hiddenInput('input-type-1', 'Additional value 1', ['id' => 'input-type-1']);
echo Html::hiddenInput('input-type-2', 'Additional value 2', ['id' => 'input-type-2']);
?>
</div>
<div class="col-3">
<?= $form->field($detail, "[{$i}]warehouse_id")->widget(DepDrop::class, [
'type' => DepDrop::TYPE_SELECT2,
//'data' =>
'options' => [
'id' => 'warehouse_id',
'placeholder' => 'Select warehouse ...',
],
'select2Options' => ['pluginOptions' => ['allowClear' => true]],
'pluginOptions' => [
'depends' => ["itemusagedetail-{$i}-item_id"],
'initialize' => true,
'url' => Url::to(['/item-sparepart/list-stock']),
'params' => ['input-type-1', 'input-type-2'],
'loadingText' => 'Loading warehouse ...',
]
]);
?>
</div>
<div class="col-2">
<?= $form->field($detail, "[{$i}]qty")->widget(MaskedInput::class,
[
'clientOptions' => [
'alias' => 'decimal',
'groupSeparator' => ',',
'digits' => 2,
'autoGroup' => true,
'removeMaskOnSubmit' => true,
'rightAlign' => false,
],
'options' => [
'class' => 'form-control',
]
]) ?>
</div>
<div class="col-3">
<?= $form->field($detail, "[{$i}]hpp")->widget(MaskedInput::class,
[
'clientOptions' => [
'alias' => 'numeric',
'groupSeparator' => ',',
'digits' => 2,
'autoGroup' => true,
'removeMaskOnSubmit' => true,
'rightAlign' => false,
],
'options' => [
'class' => 'form-control',
'onchange' => 'calculateTotal()',
]
]) ?>
</div>
</div> <!-- row -->
</div> <!-- item card-body -->
</div> <!-- item card -->
<?php endforeach; ?>
</div> <!-- card-body container-items -->
</div> <!-- card -->
<?php DynamicFormWidget::end(); ?>
<div class="form-group">
<?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>