fix(forms): getError does not work without path

This commit is contained in:
vsavkin 2015-06-09 16:05:13 -07:00
parent cee26826d7
commit a858f6ac42
2 changed files with 3 additions and 1 deletions

View File

@ -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 {

View File

@ -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);
});