Handling Disabled and Touched States
Reflect form state in your control.
Handling Disabled and Touched States is a free Angular Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Angular Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Beyond The Value
A complete custom control respects two more form concepts: disabled state and touched state. These drive UX and validation display.
setDisabledState
Angular calls setDisabledState when the form control is disabled or enabled (for example via control.disable()). Reflect it in your component.
disabled = false;
setDisabledState(isDisabled: boolean): void {
this.disabled = isDisabled;
}Reflecting Disabled In View
Use the disabled flag to style the control and block interaction so users cannot change a disabled field.
template: '<button [disabled]="disabled" (click)="select(s)">star</button>'Guarding Handlers
Also guard your change handlers so programmatic or keyboard interaction does nothing while disabled.
select(rating: number): void {
if (this.disabled) return;
this.value = rating;
this.onChange(rating);
}registerOnTouched
Angular passes a callback to mark the control as touched. Save it like you saved onChange.
private onTouched: () => void = () => {};
registerOnTouched(fn: () => void): void {
this.onTouched = fn;
}Calling onTouched
Invoke the touched callback when the user leaves the control, typically on blur. This tells Angular the user has interacted, enabling touched-based validation messages.
onBlur(): void {
this.onTouched();
}Why Touched Matters
Validation UX often shows errors only after a field is touched. Without calling onTouched, control.touched stays false and error messages may never appear at the right time.
<small *ngIf="control.touched && control.invalid">Required</small>Wiring Blur
Attach the blur handler in the template so leaving the control marks it touched.
template: '<div (blur)="onBlur()" tabindex="0">...</div>'Reactive Disable Pattern
Prefer disabling through the form API (control.disable()) rather than a template disabled binding, so Angular drives setDisabledState consistently.
this.form.get('stars')?.disable();Accessibility
Reflect disabled and focus states accessibly: set aria-disabled, manage tabindex, and ensure keyboard users can blur to trigger touched, keeping the control inclusive.
Now Fully Integrated
With value, disabled, and touched all handled, your control behaves like a native input across reactive and template-driven forms. The final piece is validation.
Quick Check
Check your disabled and touched knowledge.
Recap
You handled setDisabledState (reflect and guard against disabled) and registerOnTouched (call on blur to mark touched, enabling validation UX). Prefer the form API to drive disabled state and keep the control accessible.
Frequently asked questions
Is the “Handling Disabled and Touched States” lesson free?
Yes — the full text of “Handling Disabled and Touched States” is free to read here on the web, and the Angular Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Angular Academy course, upgrade to CoddyKit PRO.
What will I learn in “Handling Disabled and Touched States”?
Reflect form state in your control. You practise Angular Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Angular Academy?
No prior experience is required. Angular Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Handling Disabled and Touched States” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Angular Academy lesson?
Yes. Every Angular Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- The ControlValueAccessor Interface
- Writing and Registering Values
- Handling Disabled and Touched States
- Validation in Custom Controls