Skip to content

Commit abc62d4

Browse files
committed
fix: bug rendering forms
1 parent 273c71a commit abc62d4

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/index.js

+19-9
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,19 @@ async function render({ source, element, selector, data, key, index, currentInde
7171
}
7272

7373
if (source) {
74-
if (!key)
74+
if (!key) {
7575
key = source.getAttribute('render') || source.getAttribute('key')
76+
if (!key) {
77+
key = data.type
78+
if (key == 'key')
79+
key = 'object'
80+
else if (!key && data.method)
81+
key = data.method.split('.')[0]
82+
else if (!key)
83+
return
7684

85+
}
86+
}
7787
let sourceData = sources.get(source)
7888
if (!sourceData) {
7989
sourceData = { element: source, data }
@@ -93,10 +103,6 @@ async function render({ source, element, selector, data, key, index, currentInde
93103
remove = remove || data.$filter.remove
94104
}
95105

96-
let type = data.type || data.method.split('.')[0]
97-
if (type == 'key')
98-
type = 'object'
99-
100106
if (!Array.isArray(element) && !(element instanceof HTMLCollection) && !(element instanceof NodeList))
101107
element = [element]
102108

@@ -147,7 +153,6 @@ async function render({ source, element, selector, data, key, index, currentInde
147153
insertElement(renderedNode, clone, index, currentIndex)
148154
}
149155
} else {
150-
151156
// TODO: if $auto here every subsequent clone will have same value, not replacing here will apply unique value to each clone
152157
if (key === '$auto')
153158
key = key.replace(/\$auto/g, uuid.generate(6));
@@ -297,6 +302,7 @@ async function renderTemplate(template, data, key, index, keyPath) {
297302

298303
function cloneTemplate(template) {
299304
let clone = template.element.cloneNode(true);
305+
let cloneTagName = clone.tagName
300306

301307
if (clone.tagName == 'TEMPLATE') {
302308
clone = template.element.content.firstElementChild
@@ -313,12 +319,16 @@ function cloneTemplate(template) {
313319
let renderAs = clone.getAttribute('render-as')
314320
if (renderAs) {
315321
clone = clone.outerHTML.replace(/\$auto/g, renderAs);
316-
} else {
317-
clone = clone.outerHTML;
318322
}
319323

320324
if (typeof clone === 'string') {
321-
let container = document.createElement('tbody');
325+
// TODO: Some elements are only allowed a specific element, need to find these elements and confirm proper rendering.
326+
let container
327+
if (cloneTagName === 'TR')
328+
container = document.createElement('tbody');
329+
else
330+
container = document.createElement('div');
331+
322332
container.innerHTML = clone;
323333
clone = container.firstChild
324334
container.remove()

0 commit comments

Comments
 (0)