Angular Academy · Lesson

Handling Disabled and Touched States

Reflect form state in your control.

Lesson 3 of 413 steps

Handling Disabled and Touched States is a free Angular Academy lesson on CoddyKit. This is lesson 3 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Angular Academy learning path, and your progress syncs across the web and the CoddyKit app. The Angular Academy course includes 4 lessons in total.

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.

Free to start

Learn HTML with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
38
Lessons
144

Frequently Asked Questions

Is the “Handling Disabled and Touched States” lesson free?

Yes — any 3 lessons of the Angular Academy learning path, including “Handling Disabled and Touched States”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Angular Academy course includes 4 lessons in total.

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, so you can start here or from the beginning and move at your own pace. This is lesson 3 of 4.

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

  1. The ControlValueAccessor Interface
  2. Writing and Registering Values
  3. Handling Disabled and Touched States
  4. Validation in Custom Controls
← Back to Angular Academy