New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(forms): compose validator fns automatically if arrays #9168

Merged
merged 1 commit into from Jun 13, 2016

Conversation

Projects
None yet
3 participants
@kara
Contributor

kara commented Jun 13, 2016

This PR allows validator functions and async validator functions to optionally be passed in as an array.

Previously, if you wanted to pass multiple validators into a form control on instantiation, you had to compose them yourself:

class MyComp {
   myForm = new FormGroup({
      firstName: new FormControl('Nancy', Validators.required),
      lastName: new FormControl('Drew', Validators.compose([
         Validators.required, Validators.minLength(3)
      ]))
   })
}

Now you can pass in an array of validator or async validator functions directly and they will be composed for you internally. Or you can pass in a single validator function on its own, as you did before:

class MyComp {
   myForm = new FormGroup({
      firstName: new FormControl('Nancy', Validators.required),
      lastName: new FormControl('Drew', [Validators.required, Validators.minLength(3)])
   })
}

This change only applies to the new forms module (not the one currently linked in @angular/common's index.ts).

@@ -50,6 +52,15 @@ export function main() {
expect(c.valid).toEqual(false);
});
it('should support arrays of validator functions if passed', () => {
var c = new FormControl('value', [Validators.required, Validators.minLength(3)]);

This comment has been minimized.

@vsavkin

vsavkin Jun 13, 2016

Contributor

const

@@ -116,6 +127,14 @@ export function main() {
expect(c.valid).toEqual(true);
}));
it('should support arrays of async validator functions if passed', fakeAsync(() => {
var c =

This comment has been minimized.

@vsavkin

vsavkin Jun 13, 2016

Contributor

const

@kara kara merged commit 61960c5 into angular:master Jun 13, 2016

1 of 4 checks passed

ci/circleci Your tests are queued behind your running builds
Details
continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
continuous-integration/travis-ci/push The Travis CI build is in progress
Details
cla/google All necessary CLAs are signed

@kara kara deleted the kara:validators branch Jun 27, 2016

@kara kara added the comp: forms label Sep 5, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment