I wonder if it is possible to have the validation in reactive forms on blur. At the moment you can set updateOn: \"blur\"
but then the values of the input fields wo
I believe that you're looking for ng-binding on the Angular element. For example, you can bind to the keystrokes and blur like this for the input field:
eventHandler(event) {
console.log(event, event.keyCode, event.keyIdentifier);
// Update value of string on every keystroke
}
validate() {
// Validation code goes here
}
You could also use ngModel and then you wouldn't have to worry about the keystroke at all because the string would automatically be updated for you. It would look something like this:
name: string;
validate() {
// Validation code goes here
}
Since you're looking at using the Reactive Forms Module and their validation, you could do something like this:
Template Approach
The ngModel binding will change the input on every keystroke so you don't have to do it manually. I would really suggest taking this approach since this is what you're currently asking to do.
Reactive Forms Approach
this.nameForm = new FormGroup ({
firstname: new FormControl('', {
validators: Validators.required,
updateOn: 'submit'
}),
lastname: new FormControl('', {
validators: Validators.required,
updateOn: 'submit'
})
});
References: SO Approach Medium Article