refactor(forms): make Validators.group and Validators.array private
This commit is contained in:
@ -321,7 +321,15 @@ export class ControlGroup extends AbstractControl {
|
||||
_updateValue() { this._value = this._reduceValue(); }
|
||||
|
||||
/** @internal */
|
||||
_calculateControlsErrors() { return Validators.group(this); }
|
||||
_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 */
|
||||
_reduceValue() {
|
||||
@ -420,10 +428,20 @@ export class ControlArray extends AbstractControl {
|
||||
_updateValue(): void { this._value = this.controls.map((control) => control.value); }
|
||||
|
||||
/** @internal */
|
||||
_calculateControlsErrors() { return Validators.array(this); }
|
||||
_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 */
|
||||
_setParentForControls(): void {
|
||||
this.controls.forEach((control) => { control.setParent(this); });
|
||||
}
|
||||
}
|
||||
}
|
@ -54,26 +54,4 @@ export class Validators {
|
||||
return StringMapWrapper.isEmpty(res) ? null : res;
|
||||
};
|
||||
}
|
||||
|
||||
static group(group: modelModule.ControlGroup): {[key: string]: any} {
|
||||
var res: {[key: string]: any[]} = {};
|
||||
StringMapWrapper.forEach(group.controls, (control, name) => {
|
||||
if (group.contains(name) && isPresent(control.errors)) {
|
||||
res[name] = control.errors;
|
||||
}
|
||||
});
|
||||
return StringMapWrapper.isEmpty(res) ? null : res;
|
||||
}
|
||||
|
||||
static array(array: modelModule.ControlArray): any[] {
|
||||
var res: any[] = [];
|
||||
var anyErrors: boolean = false;
|
||||
array.controls.forEach((control) => {
|
||||
res.push(control.errors);
|
||||
if (isPresent(control.errors)) {
|
||||
anyErrors = true;
|
||||
}
|
||||
});
|
||||
return anyErrors ? res : null;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user