Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

256
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!