2
I’m using the function Clone jquery to replicate a div. However, when removing these elements, regardless of the amount that has been replicated, the function always removes the div by full. I need it removed row by row.
Form code:
<div class="row">
<a class="btn btn-info btn- pull-right" id="add-more-btn" title="Adicionar mais arquivos">Adicionar</a>
<a class="btn btn-warning btn-circle pull-right" id="remove-inputFile-btn">-</a>
</div>
<div class="row arquivo_upload" id="uploadArquivoId">
<div class="col-md-6" >
<?= $form->field($model, '[0]descricao')->textInput(['maxlength' => true]) ?>
</div>
<div class="col-md-6 ">
<?= $form->field($model, '[0]arquivo_url')->fileInput()?>
</div>
$('#add-more-btn').on('click', function() {
var clone = $('#uploadArquivoId').clone();
var cloneInput = clone.find('input');
var index = $('.arquivo_upload').length;
$(cloneInput[0]).attr('name', 'ArquivoDocumental['+index+'][descricao]')
$(cloneInput[1]).attr('name', 'ArquivoDocumental['+index+'][arquivo_url]')
$(cloneInput[2]).attr('name', 'ArquivoDocumental['+index+'][arquivo_url]')
$('#row-clone').append(clone);
});
$('#remove-inputFile-btn').on('click', function() {
$('#row-clone').remove();
});
When cloning
$('#uploadArquivoId')
you will repeat the id, which is incorrect.– Sam
But it is for him that I select the element that I will clone.
– user108720
You can select by class.
– Sam
I tried for class: var clone = $('.Row arquivo_upload'). clone(); But it didn’t work.
– user108720