From fad8b8bffc6a074af01325a88612a8177a016c67 Mon Sep 17 00:00:00 2001 From: Anna Sidwell Date: Wed, 23 May 2018 19:37:07 +0200 Subject: [PATCH] =?UTF-8?q?Rebuild=20multi-file=20widgets=20from=20form=20?= =?UTF-8?q?values,=20closes=C2=A0#61?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/files/static/files/upload.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/apps/files/static/files/upload.js b/apps/files/static/files/upload.js index 68a23dd..db9596d 100644 --- a/apps/files/static/files/upload.js +++ b/apps/files/static/files/upload.js @@ -38,16 +38,25 @@ class MultipleFilesWidget { } }) + // If there is something in the field, we need to restore our state + if (this.element.field.value) { + this.rebuildListFromField() + } + // Set up listening for restore this.element.field.addEventListener('change', evt => { - let idList = evt.srcElement.value.split(",") - for (let id of idList) { - this.addFile(id, id, this.setFileDone.bind(this)) - } - this.viewFileList() + this.rebuildListFromField() }) } + rebuildListFromField() { + let idList = this.element.field.value.split(",") + for (let id of idList) { + this.addFile(id, `Saved upload (id ${id})`, this.setFileDone.bind(this)) + } + this.viewFileList() + } + addFile(id, name, stateFunc) { let li = document.createElement('li') li.className = 'filewidget--file'