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,
|
Directive,
|
||||||
View,
|
View,
|
||||||
Host,
|
Host,
|
||||||
NgValidator,
|
|
||||||
forwardRef,
|
forwardRef,
|
||||||
Binding,
|
Binding,
|
||||||
EventEmitter
|
EventEmitter
|
||||||
|
|
|
@ -6,7 +6,6 @@ import {
|
||||||
Directive,
|
Directive,
|
||||||
View,
|
View,
|
||||||
Host,
|
Host,
|
||||||
NgValidator,
|
|
||||||
forwardRef,
|
forwardRef,
|
||||||
Binding
|
Binding
|
||||||
} from 'angular2/bootstrap';
|
} from 'angular2/bootstrap';
|
||||||
|
|
|
@ -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.
|
||||||
*/
|
*/
|
||||||
|
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 creditCardValidatorBinding =
|
||||||
CONST_EXPR(new Binding(NgValidator, {toAlias: forwardRef(() => CreditCardValidator)}));
|
CONST_EXPR(new Binding(NG_VALIDATORS, {toValue: creditCardValidator, multi: true}));
|
||||||
|
|
||||||
@Directive({selector: '[credit-card]', bindings: [creditCardValidatorBinding]})
|
@Directive({selector: '[credit-card]', bindings: [creditCardValidatorBinding]})
|
||||||
class CreditCardValidator {
|
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)) {
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
return {"invalidCreditCard": true};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue