fix(forms): update compose to handle null validators
This commit is contained in:
parent
bb2b961f93
commit
9d58f46ea5
|
@ -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;
|
||||
|
|
|
@ -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});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue