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.
|
||||||
*/
|
*/
|
||||||
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 {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue