You can use callback show
to make a change before displaying the repeated element.
In this callback function we can use jquery.each
to scroll through all the selects already filled, check the value and remove select which we just repeated.
show: function() {
/* Percorremos todos os selects visíveis */
$("form select:visible").each( (i, el) => {
/* Pegamos o valor do select e removemos do novo */
$(this).find('.sel option[value="${$(el).val()}"]').remove()
});
/* Exibimos o select modificado para o usuário */
$(this).slideDown();
}
Here's an example:
$(document).ready(function() {
$('.repeater').repeater({
repeaters: [{
selector: '.inner-repeater'
}],
show: function() {
$("form select:visible").each((i, el) => {
$(this).find('.sel option[value="${$(el).val()}"]').remove()
/* Bloqueia a alteração nos selects anteriores. (Opcional) */
$(el).prop("disabled", true)
});
/* Caso haja opções disponíveis, exibe para o usúario */
if ( $(this).find("option").length ) {
$(this).slideDown();
}
/* Caso contrário, bloqueia o botão "add" */
else {
$(this).parents("form").find("[data-repeater-create]").prop("disabled", true);
$(this).remove();
}
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jquery.repeater/1.2.1/jquery.repeater.min.js"></script>
<!-- outer repeater -->
<form class="repeater">
<div data-repeater-list="outer-list">
<div data-repeater-item>
<!-- innner repeater -->
<div class="inner-repeater">
<div data-repeater-list="inner-list">
<div data-repeater-item>
<select class="sel">
<option value="1" selected>Valor 1</option>
<option value="2">Valor 2</option>
<option value="3">Valor 3</option>
</select>
<input data-repeater-delete type="button" value="Delete" />
</div>
</div>
</div>
</div>
</div>
<input data-repeater-create type="button" value="Add" />
</form>