@@ -1223,8 +1223,8 @@ FIXME: real documentation
1223
1223
1224
1224
angular . module ( 'schemaForm' )
1225
1225
. directive ( 'sfSchema' ,
1226
- [ '$compile' , 'schemaForm' , 'schemaFormDecorators' , 'sfSelect' ,
1227
- function ( $compile , schemaForm , schemaFormDecorators , sfSelect ) {
1226
+ [ '$compile' , 'schemaForm' , 'schemaFormDecorators' , 'sfSelect' , 'sfPath' ,
1227
+ function ( $compile , schemaForm , schemaFormDecorators , sfSelect , sfPath ) {
1228
1228
1229
1229
var SNAKE_CASE_REGEXP = / [ A - Z ] / g;
1230
1230
var snakeCase = function ( name , separator ) {
@@ -1301,23 +1301,35 @@ angular.module('schemaForm')
1301
1301
//clean all but pre existing html.
1302
1302
element . children ( ':not(.schema-form-ignore)' ) . remove ( ) ;
1303
1303
1304
+ // Find all slots.
1305
+ var slots = { } ;
1306
+ var slotsFound = element [ 0 ] . querySelectorAll ( '*[sf-insert-field]' ) ;
1307
+
1308
+ for ( var i = 0 ; i < slotsFound . length ; i ++ ) {
1309
+ slots [ slotsFound [ i ] . getAttribute ( 'sf-insert-field' ) ] = slotsFound [ i ] ;
1310
+ }
1311
+
1304
1312
//Create directives from the form definition
1305
- angular . forEach ( merged , function ( obj , i ) {
1306
- var n = document . createElement ( attrs . sfDecorator || snakeCase ( schemaFormDecorators . defaultDecorator , '-' ) ) ;
1313
+ angular . forEach ( merged , function ( obj , i ) {
1314
+ var n = document . createElement ( attrs . sfDecorator ||
1315
+ snakeCase ( schemaFormDecorators . defaultDecorator , '-' ) ) ;
1307
1316
n . setAttribute ( 'form' , 'schemaForm.form[' + i + ']' ) ;
1308
- var slot ;
1309
- try {
1310
- slot = element [ 0 ] . querySelector ( '*[sf-insert-field="' + obj . key + '"]' ) ;
1311
- } catch ( err ) {
1312
- // field insertion not supported for complex keys
1313
- slot = null ;
1314
- }
1315
- if ( slot ) {
1316
- slot . innerHTML = "" ;
1317
- slot . appendChild ( n ) ;
1318
- } else {
1319
- frag . appendChild ( n ) ;
1317
+
1318
+ // Check if there is a slot to put this in...
1319
+ if ( obj . key ) {
1320
+ var slot = slots [ sfPath . stringify ( obj . key ) ] ;
1321
+ if ( slot ) {
1322
+ while ( slot . firstChild ) {
1323
+ slot . removeChild ( slot . firstChild ) ;
1324
+ }
1325
+ slot . appendChild ( n ) ;
1326
+ return ;
1327
+ }
1320
1328
}
1329
+
1330
+ // ...otherwise add it to the frag
1331
+ frag . appendChild ( n ) ;
1332
+
1321
1333
} ) ;
1322
1334
1323
1335
element [ 0 ] . appendChild ( frag ) ;
0 commit comments