0
I need to take the returned value of the autocomplete to make a sum in a dynamic list of products, and already does the calculation of value and quantity and now I needed to insert a new column "MEDIDA"
it is necessary to also remove the letters and take only the Qtd of the measure, I followed the code:
autocomplete
// MEDIDA
var x_medida = [
"1 UNIDADE",
"PCT 10",
"PCT 20",
"PCT 30",
"PCT 40",
"PCT 50"
];
$( ".medida" ).autocomplete({ source: x_medida });
Dynamic table
contador++;
var newRow = $("<tr>");
var cols = "";
cols += '<td class="contador valor_total" >' + contador + '</td>';
cols += '<td><label text-align="center"><input type="text" name="produto' + contador + '" class="produto" /></label></td>';
cols += '<td><label text-align="center"><input type="text" name="medida' + contador + '" class="medida centro" /></label></td>';
cols += '<td><label text-align="center"><input type="text" name="qtd' + contador + '" class="qtd centro" onkeyup="somenteNumeros(this);" /></label></td>';
cols += '<td><label text-align="center"><input type="text" name="preco' + contador + '" class="preco centro" align="center" /></label></td>';
cols += '<td class="col-md-2 centro"><b> R$ 0.00 </b></td>';
cols += '<td><a class="deleteLinha"> Excluir </a></td>';
newRow.append(cols);
$("#products-table").append(newRow);
sum of line values
// FUNCTION ( CALCULA TOTAL DA LINHA )
function calculateRow(row) {
var preco = +row.find('input[name^="preco"]').val();
var qtd = +row.find('input[name^="qtd"]').val();
//var medida = +row.find('input[name^="medida"]').val();
//2 casas decimais
var total = (preco * qtd).toFixed(2);
//substitui ponto por virgula
total = total.replace(".", ",");
//a regex abaixo coloca um ponto a esquerda de cada grupo de 3 digitos desde que não seja no inicio do numero
row.find('.total').html("R$ " + (total).replace(/\B(?=(\d{3})+(?!\d))/g, "."));
}
Perfect friend, I tried so much and it was simpler than I imagined .... kkkkk obg ae !!!
– Thiago Lopez