Skip to content

Commit a858f6a

Browse files
committed
fix(forms): getError does not work without path
1 parent cee2682 commit a858f6a

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

modules/angular2/src/forms/model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export class AbstractControl {
123123
find(path: List<string | number>| string): AbstractControl { return _find(this, path); }
124124

125125
getError(errorCode: string, path: List<string> = null) {
126-
var c = this.find(path);
126+
var c = isPresent(path) && !ListWrapper.isEmpty(path) ? this.find(path) : this;
127127
if (isPresent(c) && isPresent(c._errors)) {
128128
return StringMapWrapper.get(c._errors, errorCode);
129129
} else {

modules/angular2/test/forms/model_spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,12 +335,14 @@ export function main() {
335335
it("should return the error when it is present", () => {
336336
var c = new Control("", Validators.required);
337337
var g = new ControlGroup({"one": c});
338+
expect(c.getError("required")).toEqual(true);
338339
expect(g.getError("required", ["one"])).toEqual(true);
339340
});
340341

341342
it("should return null otherwise", () => {
342343
var c = new Control("not empty", Validators.required);
343344
var g = new ControlGroup({"one": c});
345+
expect(c.getError("invalid")).toEqual(null);
344346
expect(g.getError("required", ["one"])).toEqual(null);
345347
expect(g.getError("required", ["invalid"])).toEqual(null);
346348
});

0 commit comments

Comments
 (0)