Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

257
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda