Sub topic 17
Choosing When Values Update: change, blur, and submit
By default, a reactive form control updates its value on every keystroke. Each time it does, it runs its validators, updates its status, and emits on valueChanges. That suits most fields. Some fields need a different timing. An expensive async validator should not call the server on every key press. A long form may need to stay quiet until the user presses Save. The updateOn option sets the moment when a value moves from the view into the model.
This chapter assumes you already know FormControl, FormGroup, template binding with formControlName, validators (including async validators), and valueChanges.
The three update strategies
updateOn accepts one of three strings:
| Value | Model value, validity, and `valueChanges` update when... | `dirty` set when... | `touched` set when... |
|---|---|---|---|
| `'change'` (default) | the input fires its `input` or `change` event | on change | on blur |
| `'blur'` | the input loses focus | on blur | on blur |
| `'submit'` | the parent `<form>` fires `ngSubmit` | on submit | on submit |
The last two columns are easy to overlook. With 'blur' and 'submit', Angular keeps a pending value plus pending dirty and touched flags inside the control. It applies all of them together when the trigger happens. Until then, control.value, control.dirty, and control.errors all describe the last committed state, not what the user sees in the input. Angular has no public API for reading the pending value.
Setting updateOn on controls and groups
You can set the option on a FormControl, a FormGroup, or a FormArray. If you set it on a group or array, every descendant that has no value of its own inherits it. If you set it on a control, that control's value wins over the inherited one.
import { Component } from '@angular/core';
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
@Component({
selector: 'app-signup',
standalone: true,
imports: [ReactiveFormsModule],
template: `
<form [formGroup]="form" (ngSubmit)="onSubmit()">
<input formControlName="username" placeholder="Username" />
<input type="email" formControlName="email" placeholder="Email" />
@if (form.controls.email.touched && form.controls.email.invalid) {
<p>Enter a valid email address.</p>
}
<button type="submit">Sign up</button>
</form>
`,
})
export class SignupComponent {
form = new FormGroup(
{
// Overrides the group: commits when the field loses focus.
username: new FormControl('', {
nonNullable: true,
validators: [Validators.required],
updateOn: 'blur',
}),
// Inherits 'submit' from the group.
email: new FormControl('', {
nonNullable: true,
validators: [Validators.required, Validators.email],
}),
},
{ updateOn: 'submit' },
);
onSubmit(): void {
if (this.form.invalid) {
this.form.markAllAsTouched();
return;
}
console.log(this.form.getRawValue());
}
}When the form is submitted, FormGroupDirective commits every pending control before it emits ngSubmit. That ordering means onSubmit() always sees the values the user typed. Pressing Enter inside an input also submits the form, so the same commit happens then.
With FormBuilder, you pass the same options object:
import { inject } from '@angular/core';
import { FormBuilder, Validators } from '@angular/forms';
export function createSignupForm() {
const fb = inject(FormBuilder).nonNullable;
return fb.group(
{
username: fb.control('', { validators: [Validators.required], updateOn: 'blur' }),
email: ['', [Validators.required, Validators.email]],
},
{ updateOn: 'submit' },
);
}Call createSignupForm() from an injection context, such as a component field initializer, because it uses inject().
Using blur to throttle async validators
The most common reason to use 'blur' is an async validator. Async validators run only after the sync validators pass. With the default 'change', they still run once per keystroke, and Angular cancels the previous in-flight observable each time. With 'blur', the server check runs once, when the user leaves the field.
import { FormControl, Validators } from '@angular/forms';
import { Observable, of } from 'rxjs';
import { delay } from 'rxjs/operators';
import { usernameAvailable, UsernameChecker } from './username-available.validator';
const fakeChecker: UsernameChecker = {
isTaken: (name: string): Observable<boolean> => of(name === 'admin').pipe(delay(300)),
};
export const username = new FormControl('', {
nonNullable: true,
validators: [Validators.required, Validators.minLength(3)],
asyncValidators: [usernameAvailable(fakeChecker)],
updateOn: 'blur',
});Programmatic updates ignore updateOn
updateOn applies only to changes that come from the view, through the value accessor. Calls to setValue, patchValue, and reset commit immediately, run validators, and emit, whatever the strategy is.
import { FormControl } from '@angular/forms';
const city = new FormControl('', { nonNullable: true, updateOn: 'blur' });
city.valueChanges.subscribe((v) => console.log('valueChanges:', v));
city.setValue('Lisbon'); // logs "valueChanges: Lisbon" right away
console.log(city.value); // "Lisbon"Gotchas
Disabling the submit button deadlocks the form
[disabled]="form.invalid" is a common pattern, and it breaks under 'submit'. The required fields start empty, so the form starts invalid and the button starts disabled. Typing never commits a value, so the form never becomes valid, and the user can never submit. With 'submit', keep the button enabled and handle validity in the submit handler, as onSubmit() does above.
Error messages lag behind the input
Under 'blur', a user who fixes an invalid email still sees the error until they leave the field. Under 'submit', the error stays until the next submit. That timing can be what you want, but tell designers and testers to expect it. If your error display checks touched, remember that 'submit' also delays touched. That is why onSubmit() calls markAllAsTouched() when the form is invalid.
'submit' needs a form directive
A control bound with a standalone [formControl], with no parent <form [formGroup]>, never receives a submit event. If you set 'submit' on it, its value never commits from the view. Use 'submit' only on controls inside a formGroup form.
Custom controls must report touch
For 'blur', Angular commits when the value accessor calls its registered onTouched callback. A custom ControlValueAccessor that never calls onTouched never commits under 'blur'. A later chapter covers this interface in detail.
Choosing a strategy
- Keep
'change'for live feedback: search boxes, character counters, and fields whose value drives other parts of the UI. - Use
'blur'for fields with async or expensive validators, and for fields where errors shown while the user is still typing feel hostile. - Use
'submit'for forms whose values matter only when the user commits them, such as a settings page with a single Save button. - Mix strategies by setting the group's default and overriding it on individual controls.
Exercise
A form uses { updateOn: 'submit' } on its FormGroup, and its submit button has [disabled]="form.invalid". The form has one required field that starts empty. What happens when the user types a value, and how do you fix it?
Show answer
The button never becomes enabled. Typing stores only a pending value, so the required validator keeps seeing an empty string and the form stays invalid. The disabled button stops the submit that would commit the value. Fix it by removing the disabled binding and checking form.invalid inside the submit handler, calling markAllAsTouched() to show the errors.
Exercise
A FormGroup has { updateOn: 'blur' }. One child control has updateOn: 'change', and a second child sets no option. You call setValue('x') on the second child. When does its valueChanges emit, and when would it emit if the user typed instead?
Show answer
setValue emits immediately, because programmatic updates ignore updateOn. If the user typed, the second child would inherit 'blur' from the group and emit only when the input lost focus. The first child would emit on every keystroke because its own 'change' overrides the group.