@@ -103,7 +103,7 @@ angular.module('schemaForm').directive('schemaValidate', ['sfValidator', 'sfSele
103
103
} ) ;
104
104
105
105
106
- var DEFAULT_DESTROY_STRATEGY = getGlobalOptionsDestroyStrategy ( ) ;
106
+ /* var DEFAULT_DESTROY_STRATEGY = getGlobalOptionsDestroyStrategy();
107
107
108
108
function getGlobalOptionsDestroyStrategy() {
109
109
var defaultStrategy = undefined;
@@ -122,14 +122,49 @@ angular.module('schemaForm').directive('schemaValidate', ['sfValidator', 'sfSele
122
122
}
123
123
}
124
124
return defaultStrategy;
125
- }
125
+ }*/
126
+
126
127
127
128
// Clean up the model when the corresponding form field is $destroy-ed.
128
129
// Default behavior can be supplied as a globalOption, and behavior can be overridden in the form definition.
129
130
scope . $on ( '$destroy' , function ( ) {
131
+ console . log ( 'Schema validate destroy' , scope . externalDestructionInProgress ) ;
132
+
133
+ // If the entire schema form is destroyed we don't touch the model
134
+ if ( ! scope . externalDestructionInProgress ) {
135
+ var form = getForm ( ) ;
136
+ var destroyStrategy = form . destroyStrategy ||
137
+ ( scope . options && scope . options . destroyStrategy ) || 'remove' ;
138
+ console . log ( 'going with destroy strategy ' , destroyStrategy , scope . options )
139
+ // No key no model, and we might have strategy 'retain'
140
+ if ( form . key && destroyStrategy !== 'retain' ) {
141
+
142
+ // Get the object that has the property we wan't to clear.
143
+ var obj = scope . model ;
144
+ if ( form . key . length > 1 ) {
145
+ obj = sfSelect ( form . key . slice ( 0 , form . key . length - 1 ) , obj ) ;
146
+ }
147
+
148
+ // Type can also be a list in JSON Schema
149
+ var type = ( form . schema && form . schema . type ) || '' ;
150
+
151
+ // Empty means '',{} and [] for appropriate types and undefined for the rest
152
+ if ( destroyStrategy === 'empty' && type . indexOf ( 'string' ) !== - 1 ) {
153
+ obj [ form . key . slice ( - 1 ) ] = '' ;
154
+ } else if ( destroyStrategy === 'empty' && type . indexOf ( 'object' ) !== - 1 ) {
155
+ obj [ form . key . slice ( - 1 ) ] = { } ;
156
+ } else if ( destroyStrategy === 'empty' && type . indexOf ( 'array' ) !== - 1 ) {
157
+ obj [ form . key . slice ( - 1 ) ] = [ ] ;
158
+ } else if ( destroyStrategy === 'null' ) {
159
+ obj [ form . key . slice ( - 1 ) ] = null ;
160
+ } else {
161
+ delete obj [ form . key . slice ( - 1 ) ] ;
162
+ }
163
+ }
164
+ }
165
+
130
166
131
- var form = getForm ( ) ;
132
- var conditionResult = $parse ( form . condition ) ;
167
+ /*var conditionResult = $parse(form.condition);
133
168
var formModelNotRetained = !sfRetainModel.getFlag();
134
169
135
170
// If condition is defined and not satisfied and the sfSchema model should not be retained.
@@ -166,18 +201,8 @@ angular.module('schemaForm').directive('schemaValidate', ['sfValidator', 'sfSele
166
201
}
167
202
sfUnselect(scope.form.key, scope.model, strategy);
168
203
}
169
-
170
- function getSchemaType ( ) {
171
- var sType ;
172
- if ( form . schema ) {
173
- sType = form . schema . type ;
174
- }
175
- else {
176
- sType = null ;
177
- }
178
- return sType ;
179
- }
180
204
}
205
+ */
181
206
} ) ;
182
207
183
208
0 commit comments