Forms, Validation, and UX Flows

Professional Track: Complete this lesson with a working implementation, architecture notes, and a documented trade-off decision.

Overview

Forms are reliability surfaces. Production-grade form systems need predictable validation, explicit async states, accessibility, and clear recovery from backend errors.

Form Architecture

Controlled models

const form = ref({ email: '', fullName: '' })
const errors = ref({ email: '', fullName: '' })
const isSubmitting = ref(false)

Validation layers

  • Field-level validation: syntax and required constraints.
  • Form-level validation: cross-field rules (password confirmation, date ranges).
  • Server-level validation: authoritative business rules.

Submit Flow Design

Async submit pattern

async function submit() {
  if (!validateForm()) return
  isSubmitting.value = true
  try {
    await profileApi.update(form.value)
  } catch (error) {
    mapServerErrors(error, errors.value)
  } finally {
    isSubmitting.value = false
  }
}

UX feedback requirements

  • Disable submit button during pending requests.
  • Focus the first invalid field after validation fails.
  • Show explicit success state when save is completed.

Accessibility Rules

Labels and error associations

<label for="email">Email</label>
<input id="email" v-model="form.email" aria-describedby="emailError" />
<p id="emailError" role="alert">{{ errors.email }}</p>

Keyboard and screen-reader flow

All fields and actions must be reachable by keyboard, and errors must be announced by assistive technologies.

Learning Objectives

  • Build validated forms for create and edit workflows.
  • Handle async submit, loading, and error states.
  • Improve accessibility for keyboard and screen readers.

Common Mistakes

  • Relying only on frontend validation and ignoring backend error mapping.
  • Leaving users with silent failures and no recovery instruction.
  • Submitting duplicate requests due to missing pending state controls.

Engineering Notes

Create a reusable form utility layer for validation + error mapping to keep UX consistent across features.

Practice Scope

Deliver one production-style mini-feature, include implementation notes, and record one performance, reliability, or maintainability trade-off in your commit summary.

Back to roadmap: Vue Roadmap