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?
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>