fix(forms): update compose to handle null validators

This commit is contained in:
vsavkin 2015-10-29 17:45:24 -07:00 committed by Victor Savkin
parent bb2b961f93
commit 9d58f46ea5
2 changed files with 7 additions and 3 deletions

View File

@ -1,5 +1,4 @@
import {isBlank, isPresent} from 'angular2/src/core/facade/lang';
import {CONST_EXPR} from 'angular2/src/core/facade/lang';
import {isBlank, isPresent, CONST_EXPR} from 'angular2/src/core/facade/lang';
import {ListWrapper, StringMapWrapper} from 'angular2/src/core/facade/collection';
import {OpaqueToken} from 'angular2/src/core/di';
@ -81,7 +80,7 @@ export class Validators {
return function(control: modelModule.AbstractControl) {
var res = ListWrapper.reduce(validators, (res, validator) => {
var errors = validator(control);
var errors = isPresent(validator) ? validator(control) : null;
return isPresent(errors) ? StringMapWrapper.merge(<any>res, <any>errors) : res;
}, {});
return StringMapWrapper.isEmpty(res) ? null : res;

View File

@ -82,6 +82,11 @@ export function main() {
var c = Validators.compose([Validators.nullValidator, Validators.nullValidator]);
expect(c(new Control(""))).toEqual(null);
});
it("should ignore nulls", () => {
var c = Validators.compose([null, Validators.required]);
expect(c(new Control(""))).toEqual({"required": true});
});
});
});
}