Guest User

Untitled

a guest
May 24th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. function autoCompletar() {
  2. $('.produtoDesc').autocomplete({
  3. source: function (request, response) {
  4. $.ajax({
  5. url: '../models/retornaProduto.php',
  6. dataType: "json",
  7. data: {
  8. name_startsWith: request.term,
  9. type: 'produto'
  10. },
  11. success: function (data) {
  12. response($.map(data, function (item) {
  13. var code = item.split("|");
  14. return {
  15. label: code[0],
  16. value: code[0],
  17. data: item
  18. }
  19. }));
  20. }
  21. });
  22. },
  23. minLength: 0,
  24. select: function (event, ui) {
  25. var names = ui.item.data.split("|");
  26. $("input[name='produtoValor[]']").val(names[1]);
  27. }
  28. });
  29. };
  30.  
  31. function adicionaLinha() {
  32. var addLinha = $("#qtdLinhas")["val"]();
  33. let novoCampo;
  34. let idLinha;
  35. for (var i = 0; i < addLinha; i++) {
  36. novoCampo = $("tr.linhas:first")["clone"]();
  37. idLinha = parseInt($("tr.linhas:last").prop("id").split("item_")[1]) + 1;
  38. novoCampo.find('input').val("");
  39. novoCampo.insertAfter("tr.linhas:last").attr("id", "item_" + idLinha).find("span").html(idLinha);
  40. removeLinha();
  41. autoCompletar();
  42. }
  43. ;
  44. };
  45.  
  46. // pega todos os elementos com name produtoValor[]
  47. $("input[name='produtoValor[]']").val(names[1]);
  48.  
  49. $("input[name='produtoValor[]']", $(event.target).closest("tr")).val(names[1]);
Add Comment
Please, Sign In to add comment