Form states and built-in validators
Learn Form states and built-in validators (Module 11 · Angular Forms, Angular) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
What state is a form field in? Every control keeps FormControl states (CSS classes ng-valid , ng-dirty ... are added automatically): • pristine / dirty : dirty once the user changed the value. • untouched / touched : touched after the field loses focus (blur). • valid / invalid : all validators pass or at least one fails. Also pending (async validation running) and disabled . Good UX: show an error only when the field is invalid and touched , not as soon as the page opens.
More lessons in Module 11 · Angular Forms
- Module 11 overview and checklist
- Template-driven vs reactive forms
- Form model: FormControl, FormGroup, FormArray, FormBuilder
- Custom, cross-field and async validation, error messages
- Dynamic, nested and conditional forms, submit and reset
- Custom form controls and ControlValueAccessor
- Form accessibility, testing and performance