1
I have a form that includes lines dynamically. In this form I have a field autocomplete
where I select the product and add the product value to another input
. My problem is this: if I include two lines and select the product the value doubles in the price field (according to the image below) I would like each line included to take the value of that product.
It follows the code of autocomplete
and include lines:
function autoCompletar() {
$('.produtoDesc').autocomplete({
source: function (request, response) {
$.ajax({
url: '../models/retornaProduto.php',
dataType: "json",
data: {
name_startsWith: request.term,
type: 'produto'
},
success: function (data) {
response($.map(data, function (item) {
var code = item.split("|");
return {
label: code[0],
value: code[0],
data: item
}
}));
}
});
},
minLength: 0,
select: function (event, ui) {
var names = ui.item.data.split("|");
$("input[name='produtoValor[]']").val(names[1]);
}
});
};
function adicionaLinha() {
var addLinha = $("#qtdLinhas")["val"]();
let novoCampo;
let idLinha;
for (var i = 0; i < addLinha; i++) {
novoCampo = $("tr.linhas:first")["clone"]();
idLinha = parseInt($("tr.linhas:last").prop("id").split("item_")[1]) + 1;
novoCampo.find('input').val("");
novoCampo.insertAfter("tr.linhas:last").attr("id", "item_" + idLinha).find("span").html(idLinha);
removeLinha();
autoCompletar();
}
;
};
Solved my problem!
– Ricardo Chomicz
Wonder! Already know how the site works here when your problem has been solved?
– Sam
No, you could give me that information?
– Ricardo Chomicz