Patches form uploads to proper swap server return back into the form data
This commit is contained in:
parent
08d9cd0ff9
commit
433ac5728e
2
dist/formulate.esm.js
vendored
2
dist/formulate.esm.js
vendored
File diff suppressed because one or more lines are too long
4
dist/formulate.min.js
vendored
4
dist/formulate.min.js
vendored
File diff suppressed because one or more lines are too long
2
dist/formulate.umd.js
vendored
2
dist/formulate.umd.js
vendored
File diff suppressed because one or more lines are too long
@ -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})`
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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))
|
||||
})
|
||||
|
@ -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' &&
|
||||
|
Loading…
x
Reference in New Issue
Block a user