@@ -29,7 +29,6 @@ export default function ukNgJsonTableForm($compile, $timeout) {
29
29
} ,
30
30
link : function ( scope , element , attrs , ctrl , $transcludeFn ) {
31
31
32
-
33
32
scope . transcludeTemplate = function ( scp , elm ) {
34
33
$transcludeFn ( scp , function ( clone ) {
35
34
elm . append ( clone ) ;
@@ -67,23 +66,29 @@ export default function ukNgJsonTableForm($compile, $timeout) {
67
66
scope . newItem = { } ;
68
67
} ;
69
68
70
- scope . $watch ( 'newItem' , function ( ) {
71
- for ( let h of scope . structure ) {
72
- if ( h . type === "ratio" ) {
73
- scope . injectDefault ( h . first ) ;
74
- scope . injectDefault ( h . second ) ;
75
- } else {
76
- scope . injectDefault ( h )
77
- }
78
- }
69
+ scope . $watch ( 'parent' , function ( ) {
70
+ scope . injectDefaults ( true )
79
71
} , true ) ;
80
72
73
+ scope . $watch ( 'newItem' , function ( ) {
74
+ scope . injectDefaults ( false )
75
+ } , true ) ;
81
76
82
- scope . injectDefault = function ( h ) {
83
- if ( h . default && scope . newItem && ! scope . newItem [ h . property ] ) {
77
+ scope . injectDefault = function ( h , force ) {
78
+ if ( h . default && scope . newItem && ( ! scope . newItem [ h . property ] || force ) ) {
84
79
scope . newItem [ h . property ] = typeof h . default === "function" ? h . default ( scope . parent , scope . newItem ) : h . default ;
85
80
}
81
+ } ;
86
82
83
+ scope . injectDefaults = function ( force ) {
84
+ for ( let h of scope . structure ) {
85
+ if ( h . type === "ratio" ) {
86
+ scope . injectDefault ( h . first , force ) ;
87
+ scope . injectDefault ( h . second , force ) ;
88
+ } else {
89
+ scope . injectDefault ( h , force )
90
+ }
91
+ }
87
92
} ;
88
93
89
94
scope . removeItem = function removeItem ( index ) {
@@ -158,6 +163,7 @@ export default function ukNgJsonTableForm($compile, $timeout) {
158
163
array [ to ] = array [ from ] ;
159
164
array [ from ] = temp ;
160
165
}
166
+
161
167
}
162
168
} ;
163
169
}
0 commit comments