Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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();
- }
- ;
- };
- // pega todos os elementos com name produtoValor[]
- $("input[name='produtoValor[]']").val(names[1]);
- $("input[name='produtoValor[]']", $(event.target).closest("tr")).val(names[1]);
Add Comment
Please, Sign In to add comment