Last active
August 26, 2019 21:30
-
-
Save fininhors/335ad2384cb1889789b279c023c40fa4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function validInputByDiv(div_name) | |
| { | |
| const fields = document.querySelectorAll(`${div_name} .divObrigatorio`); | |
| const vazios = [...fields].map(field => { if (!field.value) `* O campo ${field.title} deve ser preenchido!`;}); | |
| } | |
| const itens = [...document.querySelectorAll('input[name="ckSolicitaCompra[]"]:checked')]; | |
| let valores = itens.reduce(function(filtrados, item) { | |
| if (item.checked) { | |
| filtrados.push(item.value); | |
| } | |
| return filtrados; | |
| }, []); | |
| function formataDinheiro(valor, cifrao = '') | |
| { | |
| return `${cifrao} ${valor}.toFixed(2).replace('.', ',').replace(/(\d)(?=(\d{3})+\,)/g, "$1.")`; | |
| } | |
| /* CONTADOR E LIMITADOR DE CARACTERES */ | |
| $(document).on("input keyup", "#comentario", function() { | |
| const limite = 145; | |
| const informativo = "caracteres restantes."; | |
| let caracteresDigitados = this.value.length; | |
| let caracteresRestantes = limite - caracteresDigitados; | |
| if (caracteresRestantes <= 0) { | |
| let comentario = $("textarea[name=comentario]").val(); | |
| $("textarea[name=comentario]").val(comentario.substr(0, limite)); | |
| $(".caracteres").text("0 " + informativo); | |
| } else { | |
| $(".caracteres").text(caracteresRestantes + " " + informativo); | |
| } | |
| }); | |
| let param = { | |
| prefixo : 'AXA', | |
| metodo : 'incluir', | |
| transaction: 'transactionQualquer', | |
| codigo: 21540 | |
| }; | |
| gerar(param); | |
| function gerar(...param) | |
| { | |
| $.ajax({ | |
| async : false, | |
| type : "GET", | |
| url : `../transaction/${param.transaction}`, | |
| data : { | |
| method: param.metodo, | |
| prefixo: param.prefixo, | |
| cod: $("#methodPOST").val() | |
| }, | |
| success: function(response){ | |
| document.getElementById("div_manutencao2").innerHTML = response; | |
| }, | |
| error: function(msg) { | |
| swal("Oops...", "Ocorreu um erro inesperado! "+msg, "error"); | |
| return false; | |
| } | |
| }); | |
| } | |
| function validarCamposDiv(div_nome) | |
| { | |
| let vSAlerta = "Erros ocorreram durante o envio de seu formul\xe1rio.\n\nPor favor, fa\xe7a as seguintes corre\xe7\xf5es:\n"; | |
| let mensagens_erro = []; | |
| const empty = elem.filter(elem => elem.value === ""); | |
| var div = document.getElementById('divEndereco'); | |
| var elems = [...div.querySelectorAll('.divObrigatorio')]; | |
| console.log(elems); | |
| var vazios = elems.filter(elem => elem.value !== ""); | |
| console.table(vazios); | |
| for (let field of elems) { | |
| if (!field.value) { | |
| console.log(field.name); | |
| } | |
| } | |
| $("#"+div_nome).find(".divObrigatorio").each(function(){ | |
| if($(this).val() === "" && typeof $(this).attr("title") !== undefined && typeof $(this).attr("title") !== "undefined" ) { | |
| if (vSAlerta != '') { | |
| mensagens_erro.push(vSAlerta); | |
| vSAlerta = ''; | |
| } | |
| mensagens_erro.push("* O campo "+$(this).attr("title")+" deve ser preenchido."); | |
| } | |
| $(this).addClass("ui-state-error"); | |
| $(this).on('blur', function(event) { | |
| if ($(this).val()) { | |
| $(this).removeClass("ui-state-error"); | |
| } else { | |
| $(this).addClass("ui-state-error"); | |
| } | |
| }); | |
| }); | |
| return mensagens_erro; | |
| } | |
| // Pega todos os itens com o atributo 'name' igual vSPOSICAO[] que estão checkados | |
| const vAPOSICAO = [...document.querySelectorAll('input[name="vSPOSICAO[]"]:checked')]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment