refactor(forms): update example apps to use the new way of registering validators

This commit is contained in:
vsavkin 2015-09-02 10:24:51 -07:00 committed by Victor Savkin
parent 79994b2abf
commit d43bd9b4ca
3 changed files with 10 additions and 13 deletions

View File

@ -6,7 +6,6 @@ import {
Directive, Directive,
View, View,
Host, Host,
NgValidator,
forwardRef, forwardRef,
Binding, Binding,
EventEmitter EventEmitter

View File

@ -6,7 +6,6 @@ import {
Directive, Directive,
View, View,
Host, Host,
NgValidator,
forwardRef, forwardRef,
Binding Binding
} from 'angular2/bootstrap'; } from 'angular2/bootstrap';

View File

@ -6,7 +6,7 @@ import {
Directive, Directive,
View, View,
Host, Host,
NgValidator, NG_VALIDATORS,
forwardRef, forwardRef,
Binding Binding
} from 'angular2/bootstrap'; } from 'angular2/bootstrap';
@ -32,20 +32,19 @@ class CheckoutModel {
/** /**
* Custom validator. * Custom validator.
*/ */
const creditCardValidatorBinding = function creditCardValidator(c): StringMap<string, boolean> {
CONST_EXPR(new Binding(NgValidator, {toAlias: forwardRef(() => CreditCardValidator)}));
@Directive({selector: '[credit-card]', bindings: [creditCardValidatorBinding]})
class CreditCardValidator {
get validator() { return CreditCardValidator.validate; }
static validate(c): StringMap<string, boolean> {
if (isPresent(c.value) && RegExpWrapper.test(new RegExp("^\\d{16}$"), c.value)) { if (isPresent(c.value) && RegExpWrapper.test(new RegExp("^\\d{16}$"), c.value)) {
return null; return null;
} else { } else {
return {"invalidCreditCard": true}; return {"invalidCreditCard": true};
} }
} }
const creditCardValidatorBinding =
CONST_EXPR(new Binding(NG_VALIDATORS, {toValue: creditCardValidator, multi: true}));
@Directive({selector: '[credit-card]', bindings: [creditCardValidatorBinding]})
class CreditCardValidator {
} }
/** /**