wbraganca / yii2-dynamicform

It is widget to yii2 framework to clone form elements in a nested manner, maintaining accessibility.
Other
436 stars 438 forks source link

Select2 problem on nested #336

Open MadSoul95 opened 1 year ago

MadSoul95 commented 1 year ago

Hi,

I'm currently working with a nested dynamicform where everytime I click on the add button the select2 its just empty I tried with many forms to show it after the insert and the problem persist.

This just happen on the nested one, the others works perfectly fine

This is the code for the nested dynamicform:

<?php

use yii\helpers\Html; use yii\helpers\Url; use yii\helpers\ArrayHelper; use yii\widgets\ActiveForm; use kartik\select2\Select2; use wbraganca\dynamicform\DynamicFormWidget;

use app\modules\intercentral\models\RfoCorteFibrasReserva;

?>

<?php DynamicFormWidget::begin([ 'widgetContainer' => 'dynamicform_inner', 'widgetBody' => '.container-fibras', 'widgetItem' => '.fibras-item', 'min' => 1, 'insertButton' => '.add-fibras', 'deleteButton' => '.remove-fibras', 'model' => $fibrasReserva[0], 'formId' => 'dynamic-form', 'formFields' => [ 'description' ], ]); ?>

<table class="table table-bordered">
    <thead>
        <tr>
            <th>Detalle de Cortes</th>
            <th class="text-center">
                <button type="button" class="add-fibras btn btn-success btn-xs"><span class="glyphicon glyphicon-plus"></span></button>
            </th>
        </tr>
    </thead>
    <tbody class="container-fibras">
    <?php foreach ($fibrasReserva as $i => $fibra): ?>
        <tr class="fibras-item">
            <td class="vcenter">
                <div class="col-md-12">
                    <div class="col-md-4">
                        <label>Fibra Óptica</label>
                        <?= $form->field($fibra, "[{$i}]id_fibra")->widget(Select2::Classname(),[
                            'data' => '',
                            'language' => 'es',
                            'options' => [
                                'class' => 'oc-fibra selectFibras',
                                'placeholder' => 'Seleccione una Fibra...'
                            ],
                            'pluginOptions' => [
                                'allowClear' => true
                                ],
                            ])->label(false);
                        ?>
                    </div>
                    <div class="col-md-4">
                        <label>Distancia Origen</label>
                        <?= $form->field($fibra, "[{$i}]distancia_origen")->label(false)->textInput(['maxlength' => true]) ?>
                    </div>
                    <div class="col-md-4">
                        <label>Distancia Destino</label>
                        <?= $form->field($fibra, "[{$i}]distancia_destino")->label(false)->textInput(['maxlength' => true]) ?>
                    </div>
                </div>
            </td>
            <td class="text-center vcenter" style="width: 90px;">
                <button type="button" class="remove-fibras btn btn-danger btn-xs"><span class="glyphicon glyphicon-minus"></span></button>
            </td>
        </tr>
    <?php endforeach; ?>
    </tbody>
</table>

<?php DynamicFormWidget::end(); ?>

image