0
I have a form, where I do the clone (jQuery) to add new inputs, where I can also remove them. The problem that occurs is: I need to remove the div "chain" where the remove button is. And currently I can only remove the last element.
Specific form:
Functions that adds and removes:
function addNovosArquivosUpload()
{
$('.arquivoUpload').fileinput('destroy');
var clone = $('.arquivo_upload:first').clone();
var cloneInput = clone.find('input');
var index = $('.arquivo_upload').length;
if(cloneInput.val() !== null){
cloneInput.val('');
}
clone.attr('id', 'arquivoUploadId')
$(cloneInput[0]).attr('name', 'ArquivoDocumental['+index+'][descricao]')
$(cloneInput[1]).attr('name', 'ArquivoDocumental['+index+'][arquivo_url]')
$(cloneInput[2]).attr('name', 'ArquivoDocumental['+index+'][arquivo_url]')
$(cloneInput[3]).attr('name', 'ArquivoDocumental['+index+'][arquivo_url]')
$('#row-clone').append(clone);
$('.arquivoUpload').fileinput({'language' : 'pt', 'showPreview' : false, 'showUpload' : false, 'removeLabel' : '', 'browseLabel': ''});
$('.arquivo_upload:last').append('<div class="col-md-1"><button type="button" class=" btn btn-sm btn-danger btn-rounded m-t-30 float-right" onclick="removerdivCloneArquivo();"><i class="fa fa-trash"></i></button></div>');
}
function removerdivCloneArquivo(){
$('#row-clone .arquivo_upload:last').remove();
}
Form:
<div class="row">
<button type="button" class="btn btn-info btn-rounded pull-right" onclick="addNovosArquivosUpload();" title="Adicionar mais arquivos">Adicionar</button>
</div>
<div class="row arquivo_upload">
<div class="col-md-6" >
<?= $form->field($model, '[0]descricao')->textInput(['maxlength' => true]) ?>
</div>
<div class="col-md-5">
<?= $form->field($model, '[0]arquivo_url')->widget(\kartik\file\FileInput::classname(), [
'options' => ['multiple' => true, 'class'=>'arquivoUpload'],
'language' => 'pt',
'pluginOptions' => [
'showUpload' => false,
'showPreview' => false,
'browseLabel' => '',
'removeLabel' => '',
],
])->label('Arquivo') ?>
</div>
you can give an inspect element on this screen that you put the photo, just to see how this the structure of the lines that you want to remove
– Ademilson Santana da Silva
I edited the question and added a new image.
– user108720
I made a correction to the answer. I had a small problem.
– Sam