refactor(forms): update example apps to use the new way of registering validators
This commit is contained in:
parent
79994b2abf
commit
d43bd9b4ca
|
@ -6,7 +6,6 @@ import {
|
|||
Directive,
|
||||
View,
|
||||
Host,
|
||||
NgValidator,
|
||||
forwardRef,
|
||||
Binding,
|
||||
EventEmitter
|
||||
|
|
|
@ -6,7 +6,6 @@ import {
|
|||
Directive,
|
||||
View,
|
||||
Host,
|
||||
NgValidator,
|
||||
forwardRef,
|
||||
Binding
|
||||
} from 'angular2/bootstrap';
|
||||
|
|
|
@ -6,7 +6,7 @@ import {
|
|||
Directive,
|
||||
View,
|
||||
Host,
|
||||
NgValidator,
|
||||
NG_VALIDATORS,
|
||||
forwardRef,
|
||||
Binding
|
||||
} from 'angular2/bootstrap';
|
||||
|
@ -32,20 +32,19 @@ class CheckoutModel {
|
|||
/**
|
||||
* Custom validator.
|
||||
*/
|
||||
const creditCardValidatorBinding =
|
||||
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> {
|
||||
function creditCardValidator(c): StringMap<string, boolean> {
|
||||
if (isPresent(c.value) && RegExpWrapper.test(new RegExp("^\\d{16}$"), c.value)) {
|
||||
return null;
|
||||
} else {
|
||||
return {"invalidCreditCard": true};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const creditCardValidatorBinding =
|
||||
CONST_EXPR(new Binding(NG_VALIDATORS, {toValue: creditCardValidator, multi: true}));
|
||||
|
||||
@Directive({selector: '[credit-card]', bindings: [creditCardValidatorBinding]})
|
||||
class CreditCardValidator {
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue