Skip to content

Commit c3df1f4

Browse files
committed
minified
1 parent 1b6bac1 commit c3df1f4

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

dist/schema-form.js

+28-16
Original file line numberDiff line numberDiff line change
@@ -1223,8 +1223,8 @@ FIXME: real documentation
12231223

12241224
angular.module('schemaForm')
12251225
.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) {
12281228

12291229
var SNAKE_CASE_REGEXP = /[A-Z]/g;
12301230
var snakeCase = function(name, separator) {
@@ -1301,23 +1301,35 @@ angular.module('schemaForm')
13011301
//clean all but pre existing html.
13021302
element.children(':not(.schema-form-ignore)').remove();
13031303

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+
13041312
//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, '-'));
13071316
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+
}
13201328
}
1329+
1330+
// ...otherwise add it to the frag
1331+
frag.appendChild(n);
1332+
13211333
});
13221334

13231335
element[0].appendChild(frag);

0 commit comments

Comments
 (0)