Skip to content

Commit

Permalink
fix(forms): update compose to handle null validators
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed Oct 28, 2015
1 parent c0931af commit 1571596
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 2 additions & 3 deletions modules/angular2/src/core/forms/validators.ts
@@ -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';

Expand Down Expand Up @@ -48,7 +47,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;
Expand Down
5 changes: 5 additions & 0 deletions modules/angular2/test/core/forms/validators_spec.ts
Expand Up @@ -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});
});
});
});
}

0 comments on commit 1571596

Please sign in to comment.