Skip to content

Teach forms with contact validation - #39

Merged
gpbsumido merged 4 commits into
ps/ng-07-routingfrom
ps/ng-08-forms
Nov 21, 2026
Merged

gpbsumido merged 4 commits into
ps/ng-07-routingfrom
ps/ng-08-forms

Conversation

@gpbsumido

@gpbsumido gpbsumido commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

Eighth lesson in my Angular guide: forms. The feature slice fixes the contact form's validation.

What shipped

Blank messages are rejected. A name or message of only whitespace used to pass Validators.required. A notBlank validator in shared/validators.ts now rejects it.

Send explains instead of greying out. The button is enabled except while sending. Pressing it on an invalid form runs markAllAsTouched() and moves focus to the first invalid field.

Accessible errors.

  • Each error has an id, and its input gets aria-invalid and aria-describedby while the error shows.
  • Sending, sent and failed share one role="status" region that is always in the DOM.
  • Name and email have autocomplete hints, and the form uses novalidate so Angular is the only validator.

Lesson 08: forms (/thoughts/angular-08-forms)

  • Covers the material at three levels (simple, intermediate, expert), then pitfalls and interview Q&A:
    • reactive vs template-driven forms
    • custom and cross-field validators
    • typed forms
    • accessible errors
    • async validators
    • ControlValueAccessor
    • Angular 21's experimental Signal Forms (snippet checked against the installed @angular/forms 21.2)
  • The live demo is a password pair with a group-level validator and a FormArray of links, with the status and raw value shown live.

Version and changelog. 1.4.7, with a matching changelog entry.

Commits

  1. Add failing specs for contact form validation and lesson 08
  2. Explain contact form errors instead of disabling Send
  3. Write lesson 08 with a group validator and FormArray demo
  4. Bump to 1.4.7 with the lesson 08 changelog entry

Verification

  • RED first. With the not-yet-compiling specs set aside, the RED commit had 5 contact-form failures, each for the right reason:
    • whitespace passed
    • Send was disabled
    • an invalid submit showed nothing
    • no aria-invalid
    • success wasn't in a live region
  • Spec changes since the RED commit.
    • The "Send is disabled when invalid" spec is replaced by the new behaviour.
    • The success spec checks for an enclosing role="status" rather than a role on the message itself, because a region that appears already holding text often isn't announced.
  • Tests. ng test: 59 files, 418 tests, exit 0, including axe on the contact form with every error showing.
  • Static checks. Lint and both tsc --noEmit configs are clean.
  • Production build. Exit 0, no budget warnings. Initial bundle 391.72 → 392.09 kB. Prerendered lesson 08 shows "Part 8 of 8" and the demo state INVALID.

Known gap, not in this PR

The contact form's submit is still simulated: a setTimeout reports "Message sent successfully!" without sending anything. That predates this PR and needs a real endpoint. I've kept it out of scope here.

TO-DOs for this PR

  • Before/after screenshots of the contact form after pressing Send while empty, and the lesson 08 demo, light and dark. Chromium couldn't launch in the environment I built this in.

@gpbsumido gpbsumido changed the title Teach forms with an honest contact form Teach forms with contact validation Nov 21, 2026
@gpbsumido
gpbsumido marked this pull request as ready for review November 21, 2026 15:22
@gpbsumido
gpbsumido added this pull request to stack #46 November 21, 2026 17:00
@gpbsumido
gpbsumido merged commit 530c68f into develop Nov 21, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant