From 043493cb624ee5453391cb2fd9d074ce4232d5e9 Mon Sep 17 00:00:00 2001 From: Kara Date: Thu, 1 Sep 2016 16:51:42 -0700 Subject: [PATCH] fix(forms): disabled controls should never be invalid (#11257) Closes #11253 --- modules/@angular/forms/src/model.ts | 2 +- modules/@angular/forms/test/form_control_spec.ts | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/@angular/forms/src/model.ts b/modules/@angular/forms/src/model.ts index 2b76958a63..8ae8b0583e 100644 --- a/modules/@angular/forms/src/model.ts +++ b/modules/@angular/forms/src/model.ts @@ -360,10 +360,10 @@ export abstract class AbstractControl { private _calculateStatus(): string { + if (this._allControlsDisabled()) return DISABLED; if (isPresent(this._errors)) return INVALID; if (this._anyControlsHaveStatus(PENDING)) return PENDING; if (this._anyControlsHaveStatus(INVALID)) return INVALID; - if (this._allControlsDisabled()) return DISABLED; return VALID; } diff --git a/modules/@angular/forms/test/form_control_spec.ts b/modules/@angular/forms/test/form_control_spec.ts index 4e371d8bc1..bbd735287a 100644 --- a/modules/@angular/forms/test/form_control_spec.ts +++ b/modules/@angular/forms/test/form_control_spec.ts @@ -56,6 +56,13 @@ export function main() { expect(c.status).toBe('DISABLED'); }); + it('should honor boxed value with disabled control when validating', () => { + const c = new FormControl({value: '', disabled: true}, Validators.required); + expect(c.disabled).toBe(true); + expect(c.valid).toBe(false); + expect(c.status).toBe('DISABLED'); + }); + it('should not treat objects as boxed values if they have more than two props', () => { const c = new FormControl({value: '', disabled: true, test: 'test'}, null, null); expect(c.value).toEqual({value: '', disabled: true, test: 'test'});