@@ -13,26 +13,32 @@ export default Ember.Object.extend({
13
13
} ;
14
14
this . model . addObserver ( this . property , this , this . _validate ) ;
15
15
} ,
16
- addObserversForDependentValidationKeys : Ember . on ( 'init' , function ( ) {
16
+ AfterInit : Ember . on ( 'init' , function ( ) {
17
+ this . _validate ( ) ;
18
+ this . pushDependentValidationKeyToModel ( ) ;
19
+ this . pushConditionalDependentValidationKeys ( ) ;
20
+ this . addObserversForDependentValidationKeys ( ) ;
21
+ } ) ,
22
+ addObserversForDependentValidationKeys : function ( ) {
17
23
this . dependentValidationKeys . forEach ( function ( key ) {
18
24
this . model . addObserver ( key , this , this . _validate ) ;
19
25
} , this ) ;
20
- } ) ,
21
- pushConditionalDependentValidationKeys : Ember . on ( 'init' , function ( ) {
26
+ } ,
27
+ pushConditionalDependentValidationKeys : function ( ) {
22
28
Ember . A ( [ 'if' , 'unless' ] ) . forEach ( ( conditionalKind ) => {
23
29
const conditional = this . conditionals [ conditionalKind ] ;
24
30
if ( typeof ( conditional ) === 'string' && typeof ( this . model [ conditional ] ) !== 'function' ) {
25
31
this . dependentValidationKeys . pushObject ( conditional ) ;
26
32
}
27
33
} ) ;
28
- } ) ,
29
- pushDependentValidationKeyToModel : Ember . on ( 'init' , function ( ) {
34
+ } ,
35
+ pushDependentValidationKeyToModel : function ( ) {
30
36
var model = get ( this , 'model' ) ;
31
37
if ( model . dependentValidationKeys [ this . property ] === undefined ) {
32
38
model . dependentValidationKeys [ this . property ] = Ember . A ( ) ;
33
39
}
34
40
model . dependentValidationKeys [ this . property ] . addObjects ( this . dependentValidationKeys ) ;
35
- } ) ,
41
+ } ,
36
42
call : function ( ) {
37
43
throw 'Not implemented!' ;
38
44
} ,
@@ -56,7 +62,7 @@ export default Ember.Object.extend({
56
62
}
57
63
} ) ;
58
64
} ,
59
- _validate : Ember . on ( 'init' , function ( ) {
65
+ _validate : function ( ) {
60
66
this . errors . clear ( ) ;
61
67
if ( this . canValidate ( ) ) {
62
68
this . call ( ) ;
@@ -66,7 +72,7 @@ export default Ember.Object.extend({
66
72
} else {
67
73
return Ember . RSVP . resolve ( false ) ;
68
74
}
69
- } ) ,
75
+ } ,
70
76
canValidate : function ( ) {
71
77
if ( typeof ( this . conditionals ) === 'object' ) {
72
78
if ( this . conditionals [ 'if' ] ) {
0 commit comments