Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

263
Visualizações
How can all forms validate only when I click submit?

My problem is that Angular 2/4 always validates with blur and focus instantly.

But even Google itself always validates after the first submit.

Do you know how to change the forms to only start fire validation after the first submit with a simple solution so I can use all my forms. I can create a directive, but I have not found the solution still, do you have an idea?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can do it on your onSubmit() fucntion. Here you can validate your FormControls and set manually an Error like like this example validateEmail() function.

validateEmail() {
    let invalid: boolean;
    if (this.registerForm.get("email").valid) {
      this.registerService.checkEmail(this.registerForm.get("email").value).subscribe( res => {
        invalid = res ? true : false;

        if (invalid) {
        console.log("Email is invalid: User already exists", res);
        this.registerForm.controls["email"].setErrors({invalidEmail: true});
      }
      },
      error => console.log("Error at this.registerService.checkEmail()", error))
    }
  }

In your HTML, you can check if the manually created Error is true like this and can add some Error messages to your UI:

<span *ngIf="registerForm.controls['email'].hasError('invalidEmail')" class="help-block has-error">E-Mail already exists</span>
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda