diff --git a/src/Resources/assets/admin/js/bitbag/bitbag-media-autocomplete.js b/src/Resources/assets/admin/js/bitbag/bitbag-media-autocomplete.js index a1d5260c6..d132c78b3 100644 --- a/src/Resources/assets/admin/js/bitbag/bitbag-media-autocomplete.js +++ b/src/Resources/assets/admin/js/bitbag/bitbag-media-autocomplete.js @@ -102,7 +102,11 @@ export class HandleAutoComplete { const data = await res.json(); this._addToSelectMenu(data, mediaContainer); - let children = mediaContainer.querySelector(this.selectMenu)?.children + let children = []; + let selectedContainer = mediaContainer.querySelector(this.selectMenu); + if (selectedContainer !== null) { + children = selectedContainer.children; + } for (let child of children) { child.click(); } @@ -155,9 +159,11 @@ export class HandleAutoComplete { triggerCustomEvent(mediaContainer, 'cms.media.display.update.start'); const selectMenu = mediaContainer.querySelector(this.selectMenu); selectMenu.innerHTML = ''; - arr?.forEach((item) => { - selectMenu.insertAdjacentHTML('beforeend', this._itemTemplate(item.path, item.code.trim())); - }); + if (arr !== null) { + arr.forEach((item) => { + selectMenu.insertAdjacentHTML('beforeend', this._itemTemplate(item.path, item.code.trim())); + }); + } triggerCustomEvent(mediaContainer, 'cms.media.display.update.end'); } diff --git a/src/Resources/assets/admin/js/index.js b/src/Resources/assets/admin/js/index.js index 099f9ba90..3f4948984 100644 --- a/src/Resources/assets/admin/js/index.js +++ b/src/Resources/assets/admin/js/index.js @@ -4,7 +4,7 @@ if (document.querySelector('[data-bb-target="cms-import"]')) { new HandleCsvUpload().init(); } -if (document.querySelectorAll('[data-bb-target="cms-slug-update"]')?.length > 0) { +if (document.querySelectorAll('[data-bb-target="cms-slug-update"]').length > 0) { new HandleSlugUpdate().init(); }