wbraganca/yii2-dynamicform

Select2 problem on nested

MadSoul95 opened this issue · 0 comments

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:

'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>

image