0
I have a app simple where I did some tests with the Reactive forms of Angular, and I came across the following situation: I put a console.log
in the validation function, and I realized that when trying to validate a field, every letter typed it tried to validate the field:
Validation function:
export class Validacoes {
static ValidaCpf(controle: AbstractControl) {
console.log('validated');
/* código da validação de CPF */
}
}
system logs:
Then I saw in documentation the following sentence:
We can delay updating the form validity by Changing the
updateOn
Property fromchange
(default) tosubmit
orblur
.
Which means more or less:
We can delay form validation by changing the property
updateOn
ofchange
(standard) forsubmit
orblur
.
And I changed the property, leaving the creation of my form so:
this.formulario = this.formBuilder.group({
/* campos do formulário */
}, {
/* outras opções */
updateOn: 'submit'
});
Which almost solved the problem, leaving the console like this:
But it still bothers me those three validations before I can use the form. How I remove them?
There is a project build on Github and in the Stackblitz with slight differences, but both presenting the same problem.