Skip to content

Commit

Permalink
FIO-9201: Add small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mikekotikov committed Oct 21, 2024
1 parent 9e2c616 commit a64df9c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/sdk/Formio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2379,6 +2379,8 @@ export class Formio {
rootElement
}

let hasResourceBeenAdded = false

if (!Formio.libraries.hasOwnProperty(name)) {
Formio.libraries[name] = {};
Formio.libraries[name].ready = new Promise((resolve, reject) => {
Expand All @@ -2399,6 +2401,7 @@ export class Formio {
}
else {
attachResourceToDom(resourceToDomOptions)
hasResourceBeenAdded = true;

// if no callback is provided, then check periodically for the script.
if (polling) {
Expand All @@ -2415,7 +2418,7 @@ export class Formio {

const lib = Formio.libraries[name];

if(rootElement) {
if(rootElement && !hasResourceBeenAdded) {
attachResourceToDom(resourceToDomOptions);
}

Expand Down
15 changes: 7 additions & 8 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,20 @@ export function attachResourceToDom(options: ResourceToDomOptions) {
element.setAttribute(attr, attrs[attr]);
}
}

if (rootElement) {
rootElement.insertAdjacentElement('afterend', element);
return;
}

if (onload) {
element.addEventListener('load', () => {
formio.libraries[name].loaded = true;
onload(formio.libraries[name].ready);
});
}

if (rootElement) {
rootElement.insertAdjacentElement('afterend', element);
return;
}
const { head } = document;
head.appendChild(element);
if (head) {
head.appendChild(element);
}
});
}

Expand Down

0 comments on commit a64df9c

Please sign in to comment.