Salve,
sto creando un form con righe dinamiche per aggiungere i prodotti all'ordine, ogni volta che premo sul pulsante add, viene aggiunto un nuovo rigo che clona il campo select e input, e incrementare l'array.
Per i campi input l'incremento avviene correttamente:
<input name="data[OrdersProduct][1][quantity]" class="form-control" step="0.01" value="" id="OrdersProduct1Quantity" type="number">
Mentre per il campo con la select è sempre fermo a 0
<select name="data[OrdersProduct][0][product_id]" class="form-control" id="OrdersProduct0ProductId">
Quest è lo script, sapete dirmi come posso fare per incrementare anche l'array del campo select?
codice HTML:
<script>
$(":button").click(function () {
$(".tbody tr:last-child").clone().appendTo('tbody');
$("tr:last-child").find('input').val('');
$("tr:last-child input").each(function () {
var nameAttr = $(this).attr('name');
var newIndex = parseInt(nameAttr.replace(/[^\d]/g, '')) + 1;
$(this).attr('name', nameAttr.replace(/\d/, newIndex));
var idAttr = $(this).attr('id');
var newIndex = parseInt(idAttr.replace(/[^\d]/g, '')) + 1;
$(this).attr('id', idAttr.replace(/\d/, newIndex));
});
});
$(document).on('click', '.remove', function () {
$(this).closest('tr').remove();
return false;
});
</script>