1
0
mirror of synced 2025-01-31 23:01:39 +03:00

Patches form uploads to proper swap server return back into the form data

This commit is contained in:
Justin Schroeder 2020-02-29 00:18:58 -05:00
parent 08d9cd0ff9
commit 433ac5728e
6 changed files with 18 additions and 12 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -17,6 +17,7 @@ class FileUpload {
this.options = options
this.addFileList(this.fileList)
this.context = context
this.results = false
}
/**
@ -92,6 +93,9 @@ class FileUpload {
* Perform the file upload.
*/
upload () {
if (this.results) {
return Promise.resolve(this.results)
}
return new Promise((resolve, reject) => {
if (!this.hasUploader) {
return reject(new Error('No uploader has been defined'))
@ -117,7 +121,10 @@ class FileUpload {
this.options
)
}))
.then(results => resolve(results))
.then(results => {
this.results = results
resolve(results)
})
.catch(err => { throw new Error(err) })
})
}
@ -165,7 +172,7 @@ class FileUpload {
toString () {
const descriptor = this.files.length ? this.files.length + ' files' : 'empty'
return `FileUpload(${descriptor})`
return this.results ? JSON.stringify(this.results, null, ' ') : `FileUpload(${descriptor})`
}
}

View File

@ -29,14 +29,12 @@ export default class FormSubmission {
const values = cloneDeep(this.form.internalFormModelProxy)
for (const key in values) {
if (typeof this.form.internalFormModelProxy[key] === 'object' && this.form.internalFormModelProxy[key] instanceof FileUpload) {
pending.push(this.form.internalFormModelProxy[key].upload())
pending.push(
this.form.internalFormModelProxy[key].upload().then(data => Object.assign(values, { [key]: data }))
)
}
}
/**
* @todo - how do we get these uploaded path values back into our data?
*/
Promise.all(pending)
// .then(file => file.path)
.then(() => resolve(values))
.catch(err => reject(err))
})

View File

@ -78,8 +78,9 @@ export default {
const input = this.$refs.file
if (input.files.length) {
this.context.model = this.$formulate.createUpload(input, this.context)
// nextTick required for attemptImmediateUpload to pass instanceof reliably
this.$nextTick(() => this.attemptImmediateUpload())
}
this.attemptImmediateUpload()
},
attemptImmediateUpload () {
if (this.context.uploadBehavior === 'live' &&