feat(forms): remove controlsErrors
BREAKING CHANGE Previously, the controlsErrors getter of ControlGroup and ControlArray returned the errors of their direct children. This was confusing because the result did not include the errors of nested children (ControlGroup -> ControlGroup -> Control). Making controlsErrors to include such errors would require inventing some custom serialization format, which applications would have to understand. Since controlsErrors was just a convenience method, and it was causing confusing, we are removing it. If you want to get the errors of the whole form serialized into a single object, you can manually traverse the form and accumulate the errors. This way you have more control over how the errors are serialized. Closes #5102
This commit is contained in:
@ -18,8 +18,6 @@ export abstract class AbstractControlDirective {
|
||||
return isPresent(this.control) ? this.control.errors : null;
|
||||
}
|
||||
|
||||
get controlsErrors(): any { return isPresent(this.control) ? this.control.controlsErrors : null; }
|
||||
|
||||
get pristine(): boolean { return isPresent(this.control) ? this.control.pristine : null; }
|
||||
|
||||
get dirty(): boolean { return isPresent(this.control) ? this.control.dirty : null; }
|
||||
|
@ -58,7 +58,6 @@ export abstract class AbstractControl {
|
||||
private _statusChanges: EventEmitter<any>;
|
||||
private _status: string;
|
||||
private _errors: {[key: string]: any};
|
||||
private _controlsErrors: any;
|
||||
private _pristine: boolean = true;
|
||||
private _touched: boolean = false;
|
||||
private _parent: ControlGroup | ControlArray;
|
||||
@ -77,11 +76,6 @@ export abstract class AbstractControl {
|
||||
*/
|
||||
get errors(): {[key: string]: any} { return this._errors; }
|
||||
|
||||
/**
|
||||
* Returns the errors of the child controls.
|
||||
*/
|
||||
get controlsErrors(): any { return this._controlsErrors; }
|
||||
|
||||
get pristine(): boolean { return this._pristine; }
|
||||
|
||||
get dirty(): boolean { return !this.pristine; }
|
||||
@ -126,7 +120,6 @@ export abstract class AbstractControl {
|
||||
this._updateValue();
|
||||
|
||||
this._errors = this._runValidator();
|
||||
this._controlsErrors = this._calculateControlsErrors();
|
||||
this._status = this._calculateStatus();
|
||||
|
||||
if (this._status == VALID || this._status == PENDING) {
|
||||
@ -216,7 +209,6 @@ export abstract class AbstractControl {
|
||||
|
||||
/** @internal */
|
||||
_updateControlsErrors(): void {
|
||||
this._controlsErrors = this._calculateControlsErrors();
|
||||
this._status = this._calculateStatus();
|
||||
|
||||
if (isPresent(this._parent)) {
|
||||
@ -240,8 +232,7 @@ export abstract class AbstractControl {
|
||||
|
||||
/** @internal */
|
||||
abstract _updateValue(): void;
|
||||
/** @internal */
|
||||
abstract _calculateControlsErrors(): any;
|
||||
|
||||
/** @internal */
|
||||
abstract _anyControlsHaveStatus(status: string): boolean;
|
||||
}
|
||||
@ -301,11 +292,6 @@ export class Control extends AbstractControl {
|
||||
*/
|
||||
_updateValue() {}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
_calculateControlsErrors() { return null; }
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
@ -388,17 +374,6 @@ export class ControlGroup extends AbstractControl {
|
||||
/** @internal */
|
||||
_updateValue() { this._value = this._reduceValue(); }
|
||||
|
||||
/** @internal */
|
||||
_calculateControlsErrors() {
|
||||
var res = {};
|
||||
StringMapWrapper.forEach(this.controls, (control, name) => {
|
||||
if (this.contains(name) && isPresent(control.errors)) {
|
||||
res[name] = control.errors;
|
||||
}
|
||||
});
|
||||
return StringMapWrapper.isEmpty(res) ? null : res;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
_anyControlsHaveStatus(status: string): boolean {
|
||||
var res = false;
|
||||
@ -503,19 +478,6 @@ export class ControlArray extends AbstractControl {
|
||||
/** @internal */
|
||||
_updateValue(): void { this._value = this.controls.map((control) => control.value); }
|
||||
|
||||
/** @internal */
|
||||
_calculateControlsErrors() {
|
||||
var res = [];
|
||||
var anyErrors = false;
|
||||
this.controls.forEach((control) => {
|
||||
res.push(control.errors);
|
||||
if (isPresent(control.errors)) {
|
||||
anyErrors = true;
|
||||
}
|
||||
});
|
||||
return anyErrors ? res : null;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
_anyControlsHaveStatus(status: string): boolean {
|
||||
return ListWrapper.any(this.controls, c => c.status == status);
|
||||
|
Reference in New Issue
Block a user