Skip to content

Commit

Permalink
fix(forms): getError does not work without path
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed Jun 12, 2015
1 parent cee2682 commit a858f6a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/angular2/src/forms/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class AbstractControl {
find(path: List<string | number>| string): AbstractControl { return _find(this, path); }

getError(errorCode: string, path: List<string> = 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 {
Expand Down
2 changes: 2 additions & 0 deletions modules/angular2/test/forms/model_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down

0 comments on commit a858f6a

Please sign in to comment.