From c5ba23f5590a98a230f30674ac5652f0068bd9eb Mon Sep 17 00:00:00 2001 From: Patrizio Bekerle <patrizio@bekerle.com> Date: Thu, 19 Nov 2020 11:11:02 +0100 Subject: [PATCH] Check if elements are already in the dom --- packages/file-handling/src/file-source.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/file-handling/src/file-source.js b/packages/file-handling/src/file-source.js index 261ebeca..c38d4141 100644 --- a/packages/file-handling/src/file-source.js +++ b/packages/file-handling/src/file-source.js @@ -310,8 +310,11 @@ export class FileSource extends ScopedElementsMixin(DBPLitElement) { } loadWebdavDirectory() { - if (this._('#nextcloud-file-picker').webDavClient !== null) { - this._('#nextcloud-file-picker').loadDirectory(this._('#nextcloud-file-picker').directoryPath); + const filePicker = this._('#nextcloud-file-picker'); + + // check if element is already in the dom (for example if "dialog-open" attribute is set) + if (filePicker && filePicker.webDavClient !== null) { + filePicker.loadDirectory(filePicker.directoryPath); } } @@ -320,11 +323,16 @@ export class FileSource extends ScopedElementsMixin(DBPLitElement) { this.loadWebdavDirectory(); } - MicroModal.show(this._('#modal-picker'), { - disableScroll: true, - onClose: modal => { this.isDialogOpen = false; - this._('#nextcloud-file-picker').selectAllButton = true;} - }); + const filePicker = this._('#modal-picker'); + + // check if element is already in the dom (for example if "dialog-open" attribute is set) + if (filePicker) { + MicroModal.show(filePicker, { + disableScroll: true, + onClose: modal => { this.isDialogOpen = false; + this._('#nextcloud-file-picker').selectAllButton = true;} + }); + } } closeDialog() { -- GitLab