Skip to content

Commit d43bd9b

Browse files
committed
refactor(forms): update example apps to use the new way of registering validators
1 parent 79994b2 commit d43bd9b

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

modules/examples/src/order_management/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
Directive,
77
View,
88
Host,
9-
NgValidator,
109
forwardRef,
1110
Binding,
1211
EventEmitter

modules/examples/src/person_management/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
Directive,
77
View,
88
Host,
9-
NgValidator,
109
forwardRef,
1110
Binding
1211
} from 'angular2/bootstrap';

modules/examples/src/template_driven_forms/index.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
Directive,
77
View,
88
Host,
9-
NgValidator,
9+
NG_VALIDATORS,
1010
forwardRef,
1111
Binding
1212
} from 'angular2/bootstrap';
@@ -32,20 +32,19 @@ class CheckoutModel {
3232
/**
3333
* Custom validator.
3434
*/
35+
function creditCardValidator(c): StringMap<string, boolean> {
36+
if (isPresent(c.value) && RegExpWrapper.test(new RegExp("^\\d{16}$"), c.value)) {
37+
return null;
38+
} else {
39+
return {"invalidCreditCard": true};
40+
}
41+
}
42+
3543
const creditCardValidatorBinding =
36-
CONST_EXPR(new Binding(NgValidator, {toAlias: forwardRef(() => CreditCardValidator)}));
44+
CONST_EXPR(new Binding(NG_VALIDATORS, {toValue: creditCardValidator, multi: true}));
3745

3846
@Directive({selector: '[credit-card]', bindings: [creditCardValidatorBinding]})
3947
class CreditCardValidator {
40-
get validator() { return CreditCardValidator.validate; }
41-
42-
static validate(c): StringMap<string, boolean> {
43-
if (isPresent(c.value) && RegExpWrapper.test(new RegExp("^\\d{16}$"), c.value)) {
44-
return null;
45-
} else {
46-
return {"invalidCreditCard": true};
47-
}
48-
}
4948
}
5049

5150
/**

0 commit comments

Comments
 (0)