Advanced Patterns
Complex form scenarios with multi-step wizards, dynamic fields, conditional validation, and more.
What you'll learn...
Multi-step wizard forms with progress tracking
Dynamic forms (add/remove fields at runtime)
Conditional validation based on field dependencies
Form state management (dirty, pristine, touched)
Autosave and draft management
Complex file uploads with preview and progress
Form arrays (repeating field groups)
Prerequisites
All examples assume you have the validation plugin installed and configured:
npm install @aurelia/validation @aurelia/validation-html// src/main.ts
import Aurelia from 'aurelia';
import { ValidationHtmlConfiguration } from '@aurelia/validation-html';
Aurelia.register(ValidationHtmlConfiguration)
.app(component)
.start();See Validation documentation for setup details.
Multi-Step Wizard Forms
Multi-step forms break complex forms into manageable steps, improving user experience and completion rates.
Complete Example: User Onboarding Wizard
Key Features:
Step-by-step validation (only validate current step)
Progress indicator
Conditional validation rules with
.when()Navigate to first step with errors on final submit
Accessible navigation buttons
Dynamic Forms (Add/Remove Fields)
Forms where users can add or remove fields at runtime, like adding multiple email addresses or phone numbers.
Complete Example: Contact Form with Dynamic Emails
Key Features:
Add/remove email entries dynamically
Ensure at least one email exists
Automatically handle primary email when removing
Validate all emails in the array
Unique IDs for each entry (accessibility and key binding)
Conditional Validation (Field Dependencies)
Validation rules that change based on the values of other fields.
Complete Example: Shipping Form
Key Features:
Conditional field visibility with
if.bindConditional validation with
.when()Fields depend on checkbox state
Fields depend on select values
Automatic revalidation when dependencies change
Form State Management (Dirty, Pristine, Touched)
Track whether forms have been modified and warn users before losing changes.
Complete Example: Article Editor with Unsaved Changes Warning
Key Features:
Dirty state tracking (compare current vs original)
Autosave to localStorage every 30 seconds
Last saved timestamp with human-readable formatting
Prevent navigation with
canUnloadrouter hookVisual indicators for save state
Disable actions while saving
Form Arrays (Repeating Field Groups)
Form arrays allow users to add/remove entire groups of fields, like invoice line items or multiple addresses.
Complete Example: Invoice Form with Line Items
Key Features:
Add/remove line items dynamically
Duplicate line items
Auto-calculate line totals and invoice totals
Validate entire array of items
Prevent removing last item
Unique IDs for each line item
Accessible labels for screen readers
Complex File Uploads with Preview & Progress
Handle multiple file uploads with image previews, progress tracking, and validation.
Complete Example: Image Gallery Upload
Key Features:
Drag & drop support
Image preview generation
Progress tracking for each file
File type and size validation
Multiple file selection
Individual or bulk upload
Error handling per file
Visual status indicators
Dependent Dropdowns (Cascading Selects)
Dropdowns where options depend on previous selections, like country → state → city.
Complete Example: Location Selector
Key Features:
Cascading selects (country → state → city)
Computed properties for filtered options
Auto-reset dependent fields when parent changes
Loading states while fetching options
Disabled state until parent is selected
Helpful hints for users
Reusable Form Field Components
Create reusable form field components that encapsulate label, input, validation, and error display.
Complete Example: Validated Text Field Component
Usage Example
Key Features:
Encapsulates label, input, validation, error display
Reusable across entire application
Consistent styling and behavior
Accessible (proper ARIA attributes)
Reduced boilerplate in forms
Related Documentation
Form Basics - Basic form concepts
Validation Plugin - Complete validation guide
Form Submission - Handling form submission
Collections (Checkboxes, Radios, Select) - Working with form collections
File Uploads - File upload patterns
Summary
These advanced patterns handle complex real-world scenarios:
Multi-step wizards - Break complex forms into manageable steps with conditional validation and progress tracking
Dynamic forms - Add/remove individual fields at runtime with validation
Conditional validation - Validation rules that depend on other field values
Form state management - Track changes, prevent data loss, implement autosave with router guards
Form arrays - Repeating field groups (like invoice line items) with add/remove/duplicate functionality
Complex file uploads - Multiple file uploads with drag & drop, previews, progress tracking, and per-file validation
Dependent dropdowns - Cascading selects (country → state → city) with auto-reset and loading states
Reusable form fields - Encapsulated field components with built-in validation display
All examples use proper Aurelia 2 syntax with the validation plugin and follow accessibility best practices. Each pattern includes complete, production-ready code with TypeScript interfaces, validation rules, and accessible HTML templates.
Last updated
Was this helpful?