Rebuild multi-file widgets from form values, closes #61

This commit is contained in:
Anna Sidwell 2018-05-23 19:37:07 +02:00
parent b375de115e
commit fad8b8bffc

View File

@ -38,14 +38,23 @@ 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(",")
this.rebuildListFromField()
})
}
rebuildListFromField() {
let idList = this.element.field.value.split(",")
for (let id of idList) {
this.addFile(id, id, this.setFileDone.bind(this))
this.addFile(id, `Saved upload (id ${id})`, this.setFileDone.bind(this))
}
this.viewFileList()
})
}
addFile(id, name, stateFunc) {