2
I have the form below which when I click Add more Pet, he adds one more panel normally:
But when I click Remove, it removes only buttons and panels continue. See code:
<table border="0" style="width: 100%">
<tr class='linhas'>
<td>
<div class="panel panel-primary">
<div class="panel-heading">
<i class="fa fa-paw fa-lg" aria-hidden="true"></i> DADOS DO PET
</div>
<div class="panel-body">
<div class="table-responsive">
<div class="form-group">
<label>Espécie:</label>
<select name="Especie" class="form-control">
<option value="Canino">Canino</option>
<option value="Felino">Felino</option>
</select>
</div>
<div class="form-group">
<label>Nome do Pet:</label>
<input type="text" name="NomePet" class="form-control" required="required">
</div>
<div class="form-group">
<label>Aniversário do Pet:</label>
<input type="date" name="AniversarioPet" class="form-control" data-inputmask="'alias': '99/99/9999'" required="required">
</div>
<div class="form-group">
<label>Gênero:</label>
<div class="checkbox">
<label><input type="radio" name="SexoPet" value="Macho" checked> Macho</label>
<label><input type="radio" name="SexoPet" value="Fêmea"> Fêmea</label>
</div>
</div>
<div class="form-group">
<label>Idade:</label>
<select name="IdadePet" class="form-control">
<option value="Antes dos 11 meses">Antes dos 11 meses</option>
<option value="Entre 1 e 8 anos">Entre 1 e 8 anos</option>
</select>
</div>
</div>
</div>
</div>
</td>
</tr>
<tr>
<td>
<button type="button" class="adicionarCampo btn btn-primary" title="Adicionar item"><i class="fa fa-plus-square" aria-hidden="true"></i> Adicionar mais Pet</button>
<button type="button" class="removerCampo btn btn-danger" title="Remover linha"><i class="fa fa-minus-square" aria-hidden="true"></i> Remover</button>
</td>
</tr>
</table>
JQUERY
<script type="text/javascript">
$(function () {
function removeCampo() {
$(".removerCampo").unbind("click");
$(".removerCampo").bind("click", function () {
if($("tr.linhas").length > 1){
$(this).parent().parent().remove();
}
});
}
$(".adicionarCampo").click(function () {
novoCampo = $("tr.linhas:first").clone();
novoCampo.find('input[type="text"]').val("");
novoCampo.find('select').val("");
novoCampo.insertAfter("tr.linhas:last");
removeCampo();
});
});
</script>
What I find strange is when I put the line down inside a TD as another column where the panel is, works:
<button type="button" class="removerCampo btn btn-danger" title="Remover linha"><i class="fa fa-minus-square" aria-hidden="true"></i> Remover</button>
How can I fix this?
Fox puts the CSS? also for me to assemble the fiddle? much better bro. Thanks
– Leonardo Bonetti
Hello Leonardo. I’m actually using Bootstrap. I don’t have a specific CSS for it. It’s just these codes that make up the question even.
– user24136
All right, it was more my habit of leaving the cute fiddle kkk, I solved the problem I’m just explaining why you were behaving like that 1min.
– Leonardo Bonetti