fix(forms): clear errors on disable (#11463)

Closes #11287
This commit is contained in:
Kara
2016-09-09 12:00:38 -07:00
committed by Evan Martin
parent f386cb4ba9
commit 673de004d2
4 changed files with 188 additions and 30 deletions

View File

@ -190,6 +190,7 @@ export abstract class AbstractControl {
emitEvent = isPresent(emitEvent) ? emitEvent : true;
this._status = DISABLED;
this._errors = null;
this._forEachChild((control: AbstractControl) => { control.disable({onlySelf: true}); });
this._updateValue();
@ -232,17 +233,16 @@ export abstract class AbstractControl {
onlySelf = normalizeBool(onlySelf);
emitEvent = isPresent(emitEvent) ? emitEvent : true;
this._setInitialStatus();
this._updateValue();
this._errors = this._runValidator();
const originalStatus = this._status;
this._status = this._calculateStatus();
if (this._status == VALID || this._status == PENDING) {
this._runAsyncValidator(emitEvent);
}
if (this.enabled) {
this._errors = this._runValidator();
this._status = this._calculateStatus();
if (this._disabledChanged(originalStatus)) {
this._updateValue();
if (this._status === VALID || this._status === PENDING) {
this._runAsyncValidator(emitEvent);
}
}
if (emitEvent) {
@ -261,6 +261,8 @@ export abstract class AbstractControl {
this.updateValueAndValidity({onlySelf: true, emitEvent});
}
private _setInitialStatus() { this._status = this._allControlsDisabled() ? DISABLED : VALID; }
private _runValidator(): {[key: string]: any} {
return isPresent(this.validator) ? this.validator(this) : null;
}
@ -281,11 +283,6 @@ export abstract class AbstractControl {
}
}
private _disabledChanged(originalStatus: string): boolean {
return this._status !== originalStatus &&
(this._status === DISABLED || originalStatus === DISABLED);
}
/**
* Sets errors on a form control.
*