From a858f6ac42a08587ee0c9fb43e4367e351764531 Mon Sep 17 00:00:00 2001 From: vsavkin Date: Tue, 9 Jun 2015 16:05:13 -0700 Subject: [PATCH] fix(forms): getError does not work without path --- modules/angular2/src/forms/model.ts | 2 +- modules/angular2/test/forms/model_spec.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/angular2/src/forms/model.ts b/modules/angular2/src/forms/model.ts index 6ae5000576..ee06b8cf09 100644 --- a/modules/angular2/src/forms/model.ts +++ b/modules/angular2/src/forms/model.ts @@ -123,7 +123,7 @@ export class AbstractControl { find(path: List| string): AbstractControl { return _find(this, path); } getError(errorCode: string, path: List = null) { - var c = this.find(path); + var c = isPresent(path) && !ListWrapper.isEmpty(path) ? this.find(path) : this; if (isPresent(c) && isPresent(c._errors)) { return StringMapWrapper.get(c._errors, errorCode); } else { diff --git a/modules/angular2/test/forms/model_spec.ts b/modules/angular2/test/forms/model_spec.ts index 7a100b9e0d..c7dbc6e7fd 100644 --- a/modules/angular2/test/forms/model_spec.ts +++ b/modules/angular2/test/forms/model_spec.ts @@ -335,12 +335,14 @@ export function main() { it("should return the error when it is present", () => { var c = new Control("", Validators.required); var g = new ControlGroup({"one": c}); + expect(c.getError("required")).toEqual(true); expect(g.getError("required", ["one"])).toEqual(true); }); it("should return null otherwise", () => { var c = new Control("not empty", Validators.required); var g = new ControlGroup({"one": c}); + expect(c.getError("invalid")).toEqual(null); expect(g.getError("required", ["one"])).toEqual(null); expect(g.getError("required", ["invalid"])).toEqual(null); });