5
Test scenario
function addReg(){
var reg = $('#registro').clone().removeAttr('id');
reg.children('label').remove();
$('#formX').append(reg);
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container">
<div class="row">
<form id="formX" method="get" action="kk.php">
<div id="registro" class="form-row">
<div class="form-group mr-2">
<label for="origem">Origem</label>
<select id="origem" class="form-control" tabindex="-1" name="origem">
<option selected>Selecione...</option>
<option>Item 1</option>
<option>Item 2</option>
<option>Item 3</option>
</select>
</div>
<div class="form-group mr-2">
<label for="destino">Destino</label>
<select id="destino" class="form-control" tabindex="-1" name="destino">
<option selected>Selecione...</option>
<option>Item 1</option>
<option>Item 2</option>
<option>Item 3</option>
</select>
</div>
<div class="form-group mr-2">
<label for="item">Item</label>
<select id="item" class="form-control" tabindex="-1" name="item">
<option selected>Selecione...</option>
<option>Item 1</option>
<option>Item 2</option>
<option>Item 3</option>
</select>
</div>
<div class="form-group mr-2">
<label for="hora">Hora</label>
<input id="hora" type="time" class="form-control" name="hora">
</div>
<div class="form-group col-md-1">
<div class="form-check form-check-inline" style="padding-top: 40px;">
<input class="form-check-input" type="checkbox" id="bf" value="bf" tabindex="-1">
<label class="form-check-label" for="bf"><b>BF</b></label>
</div>
</div>
</div>
</form>
</div>
<div class="row">
<button form="formX" type="submit" class="btn btn-primary mr-3" tabindex="-1">Salvar</button>
<button class="btn btn-info" onclick="addReg()" tabindex="-1">+</button>
</div>
</div>
Problems
When I clone, it does not bring the values of the elements select
.
Also, keeps the elements label
, of course, because I am copying everything. I have tried to remove but could not.
Doubts
- How do I keep the selected value of the elements
select
? - How do I always clone the "last clone"? (I remove the id from the previous one and add it to the cloned one?)
- How do I delete the elements
label
(of the type elementsinput
) not to duplicate them?
In short: you want the last selected values to be used when cloning and without the Abels?
– Woss
@Andersoncarloswoss that! rs
– rbz
And the "BF", will remove tb?
– Sam
@Sam No, the BF keeps!
– rbz