fix(forms): getError does not work without path
This commit is contained in:
		
							parent
							
								
									cee26826d7
								
							
						
					
					
						commit
						a858f6ac42
					
				| @ -123,7 +123,7 @@ export class AbstractControl { | |||||||
|   find(path: List<string | number>| string): AbstractControl { return _find(this, path); } |   find(path: List<string | number>| string): AbstractControl { return _find(this, path); } | ||||||
| 
 | 
 | ||||||
|   getError(errorCode: string, path: List<string> = null) { |   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)) { |     if (isPresent(c) && isPresent(c._errors)) { | ||||||
|       return StringMapWrapper.get(c._errors, errorCode); |       return StringMapWrapper.get(c._errors, errorCode); | ||||||
|     } else { |     } else { | ||||||
|  | |||||||
| @ -335,12 +335,14 @@ export function main() { | |||||||
|           it("should return the error when it is present", () => { |           it("should return the error when it is present", () => { | ||||||
|             var c = new Control("", Validators.required); |             var c = new Control("", Validators.required); | ||||||
|             var g = new ControlGroup({"one": c}); |             var g = new ControlGroup({"one": c}); | ||||||
|  |             expect(c.getError("required")).toEqual(true); | ||||||
|             expect(g.getError("required", ["one"])).toEqual(true); |             expect(g.getError("required", ["one"])).toEqual(true); | ||||||
|           }); |           }); | ||||||
| 
 | 
 | ||||||
|           it("should return null otherwise", () => { |           it("should return null otherwise", () => { | ||||||
|             var c = new Control("not empty", Validators.required); |             var c = new Control("not empty", Validators.required); | ||||||
|             var g = new ControlGroup({"one": c}); |             var g = new ControlGroup({"one": c}); | ||||||
|  |             expect(c.getError("invalid")).toEqual(null); | ||||||
|             expect(g.getError("required", ["one"])).toEqual(null); |             expect(g.getError("required", ["one"])).toEqual(null); | ||||||
|             expect(g.getError("required", ["invalid"])).toEqual(null); |             expect(g.getError("required", ["invalid"])).toEqual(null); | ||||||
|           }); |           }); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user