feat(validations): add support to bind dir validators #11116

wants to merge 2 commits into


None yet

4 participants

kara commented Aug 27, 2016 edited

This PR builds on @tolemac's original PR to finish adding support for dir validators. He's done most of the work here; just putting on finishing touches.

r: @IgorMinar, @vsavkin

Summary: Previously, it wasn't possible to bind to validators like required, minlength, maxlength, and pattern in the DOM. If you did the following:

<input name="first" ngModel [required]="isRequired">

...regardless of the value of isRequired, validation would be run as if required were set. This is because the built-in validator directives weren't set up to respond to inputs and to re-run validation when those inputs changed. Now the above should work!

@tolemac tolemac feat(validations): add support to bind validation attributes
This change enables to bind the validations attributes `required`,
`minlength`, `maxlength` and `pattern`.

Closes: #10505, #7393

We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm.

@googlebot googlebot added the cla: no label Aug 27, 2016
@vsavkin vsavkin was assigned by kara Aug 27, 2016
@kara kara referenced this pull request Aug 27, 2016

feat(validations): add support to bind validation attributes #10518

2 of 3 tasks complete
@vsavkin vsavkin and 1 other commented on an outdated diff Aug 27, 2016
@@ -30,6 +30,7 @@ export abstract class NgControl extends AbstractControlDirective {
get validator(): ValidatorFn { return <ValidatorFn>unimplemented(); }
get asyncValidator(): AsyncValidatorFn { return <AsyncValidatorFn>unimplemented(); }
+ get rawValidators(): any[] { return unimplemented(); }
vsavkin Aug 27, 2016 Contributor

why any[]?

kara Aug 27, 2016 edited Contributor

Oh, I think it should be Array<Validator|ValidatorFn>. I can update.

@vsavkin vsavkin commented on an outdated diff Aug 29, 2016
@@ -105,6 +105,8 @@ export class NgModel extends NgControl implements OnChanges,
get validator(): ValidatorFn { return composeValidators(this._validators); }
+ get rawValidators(): Array<Validator|ValidatorFn> { return this._validators || []; }
vsavkin Aug 29, 2016 Contributor

Why do we include only sync validators here?

vsavkin commented Aug 29, 2016 edited

We're doing it this way because we don't it to be a breaking change? I find it a bit weird to have three properties instead of two.

Cause we could have had two properties validators and asyncValidators and compose them elsewhere, but it would be a breaking change.

@kara kara fix(forms): update validity when validator dir changes
@kara kara added this to the 2.0.0-rc.6 milestone Aug 29, 2016
@vicb vicb closed this in d2ad871 Aug 29, 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