From e7b694101d789c69f292bb2a86445028e921afb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9?= Date: Mon, 31 May 2021 12:59:25 -0300 Subject: [PATCH] validar cpf em editar projeto --- resources/views/projeto/editar.blade.php | 142 ++++++++++++++++++++--- 1 file changed, 125 insertions(+), 17 deletions(-) diff --git a/resources/views/projeto/editar.blade.php b/resources/views/projeto/editar.blade.php index ce7e793..670dd07 100644 --- a/resources/views/projeto/editar.blade.php +++ b/resources/views/projeto/editar.blade.php @@ -431,12 +431,14 @@
- - @error('cpf1') - - {{ $message }} + + + - @enderror +
@@ -689,12 +691,14 @@
- - @error('cpf2') - - {{ $message }} + + + + - @enderror
@@ -945,12 +949,14 @@
- - @error('cpf3') - - {{ $message }} + + + + - @enderror
@@ -1228,6 +1234,27 @@
+ + + @endsection @section('javascript') @@ -1490,16 +1517,19 @@ function fecharModalenviarProjeto(){ function enviarModalenviarProjeto(){ if(numeroDeParticipantes == 1){ document.getElementById("collapseParticipante1").classList.add("show"); - document.getElementById("clickSubmitForm").click(); }else if(numeroDeParticipantes == 2){ document.getElementById("collapseParticipante1").classList.add("show"); document.getElementById("collapseParticipante2").classList.add("show"); - document.getElementById("clickSubmitForm").click(); }else if(numeroDeParticipantes == 3){ document.getElementById("collapseParticipante1").classList.add("show"); document.getElementById("collapseParticipante2").classList.add("show"); document.getElementById("collapseParticipante3").classList.add("show"); + } + + if (checarCpfs()) { document.getElementById("clickSubmitForm").click(); + } else { + $("#modalCpfInvalido").modal('show'); } } /* @@ -2057,5 +2087,83 @@ function validarPart3(){ // } // }); // }); + $(document).ready(function(){ + $(".cpf").change(function(){ + if (validarCPF(retirarFormatacao(this.value))) { + this.parentElement.children[2].style.display = "none"; + this.parentElement.children[3].style.display = "block"; + } else { + this.parentElement.children[2].style.display = "block"; + this.parentElement.children[3].style.display = "none"; + } + }); + }); + + function validarCPF(strCPF) { + var soma; + var resto; + soma = 0; + // Verifica se foi informado todos os digitos corretamente + if (strCPF.length != 11) { + return false; + } + + // Verifica se foi informada uma sequência de digitos repetidos. Ex: 111.111.111-11 + if (varificarDigitos(strCPF)) { + return false; + } + + // Faz o calculo para validar o CPF + for (var t = 9; t < 11; t++) { + for (var d = 0, c = 0; c < t; c++) { + d += strCPF[c] * ((t + 1) - c); + } + d = ((10 * d) % 11) % 10; + if (strCPF[c] != d) { + return false; + } + } + return true; + } + + function retirarFormatacao(strCpf) { + resultado = ""; + for(var i = 0; i < strCpf.length; i++) { + if (strCpf[i] != "." && strCpf[i] != "-") { + resultado += strCpf[i]; + } + } + return resultado; + } + + function varificarDigitos(strCpf) { + var cont = 1; + dig1 = strCpf[0]; + + for(var i = 1; i < strCpf.length; i++) { + if(dig1 == strCpf[i]) { + cont++; + } + } + if (cont == strCpf.length) { + return true; + } + return false; + } + + function checarCpfs() { + var validacoes = document.getElementsByClassName("cpf-invalido"); + var count = validacoes.length; + var quant = 0; + for(var i = 0; i < validacoes.length; i++) { + if (validacoes[i].style.display == "none") { + quant++; + } + } + if(quant == count) { + return true; + } + return false; + } @endsection -- GitLab