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:
vsavkin
2015-11-03 12:56:34 -08:00
committed by Victor Savkin
parent 4439106a1f
commit 7343ef04ae
4 changed files with 1 additions and 123 deletions
@@ -302,7 +302,6 @@ export function main() {
c.setErrors({"someError": true});
expect(g.controlsErrors).toEqual({"one": {"someError": true}});
expect(g.valid).toEqual(false);
});
@@ -354,41 +353,6 @@ export function main() {
});
});
describe("controlsErrors", () => {
it("should be null when no errors", () => {
var g = new ControlGroup({"one": new Control('value', Validators.required)});
expect(g.valid).toEqual(true);
expect(g.controlsErrors).toEqual(null);
});
it("should collect errors from the child controls", () => {
var one = new Control(null, Validators.required);
var g = new ControlGroup({"one": one});
expect(g.valid).toEqual(false);
expect(g.controlsErrors).toEqual({"one": {"required": true}});
});
it("should not include controls that have no errors", () => {
var one = new Control(null, Validators.required);
var two = new Control("two");
var g = new ControlGroup({"one": one, "two": two});
expect(g.controlsErrors).toEqual({"one": {"required": true}});
});
it("should run the validator with the value changes", () => {
var c = new Control(null, Validators.required);
var g = new ControlGroup({"one": c});
c.updateValue("some value");
expect(g.valid).toEqual(true);
expect(g.controlsErrors).toEqual(null);
});
});
describe("errors", () => {
it("should run the validator when the value changes", () => {
var simpleValidator = (c) =>
@@ -667,39 +631,6 @@ export function main() {
});
});
describe("controlsErrors", () => {
it("should return null when no errors", () => {
var a = new ControlArray(
[new Control(1, Validators.required), new Control(2, Validators.required)]);
expect(a.valid).toBe(true);
expect(a.controlsErrors).toBe(null);
});
it("should collect errors from the child controls", () => {
var a = new ControlArray([
new Control(1, Validators.required),
new Control(null, Validators.required),
new Control(2, Validators.required)
]);
expect(a.valid).toBe(false);
expect(a.controlsErrors).toEqual([null, {"required": true}, null]);
});
it("should run the validator when the value changes", () => {
var a = new ControlArray([]);
var c = new Control(null, Validators.required);
a.push(c);
expect(a.valid).toBe(false);
c.updateValue("some value");
expect(a.valid).toBe(true);
expect(a.controlsErrors).toBe(null);
});
});
describe("errors", () => {
it("should run the validator when the value changes", () => {
var simpleValidator = (c) => c.controls[0].value != "correct" ? {"broken": true} : null;