Pre-fill support for file input (#222)

Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
formsdev
2023-10-20 14:30:35 +05:30
committed by GitHub
parent c470791282
commit 4614dc0f18
6 changed files with 63 additions and 17 deletions

View File

@@ -156,6 +156,7 @@
<script>
import Modal from '../Modal.vue'
import axios from 'axios'
import inputMixin from '~/mixins/forms/input.js'
export default {
@@ -166,7 +167,8 @@ export default {
props: {
multiple: { type: Boolean, default: true },
mbLimit: { type: Number, default: 5 },
accept: { type: String, default: '' }
accept: { type: String, default: '' },
moveToFormAssets: { type: Boolean, default: false }
},
data: () => ({
@@ -271,12 +273,30 @@ export default {
if (!this.multiple) {
this.files = []
}
this.files.push({
file: file,
url: file.name.split('.').slice(0, -1).join('.') + '_' + response.uuid + '.' + response.extension
})
this.showUploadModal = false
this.loading = false
if (this.moveToFormAssets) {
// Move file to permanent storage for form assets
axios.post('/api/open/forms/assets/upload', {
type: 'files',
url: file.name.split('.').slice(0, -1).join('.') + '_' + response.uuid + '.' + response.extension
}).then(moveFileResponse => {
this.files.push({
file: file,
url: moveFileResponse.data.url
})
this.showUploadModal = false
this.loading = false
}).catch((error) => {
this.showUploadModal = false
this.loading = false
})
} else {
this.files.push({
file: file,
url: file.name.split('.').slice(0, -1).join('.') + '_' + response.uuid + '.' + response.extension
})
this.showUploadModal = false
this.loading = false
}
}).catch((error) => {
this.clearAll()
this.showUploadModal = false

View File

@@ -265,7 +265,12 @@
:form="field"
label="Pre-filled value"
/>
<text-input v-else-if="field.type!=='files'" name="prefill" class="mt-3"
<file-input v-else-if="field.type==='files'" name="prefill" class="mt-4"
:form="field"
label="Pre-filled file"
:multiple="field.multiple===true" :moveToFormAssets="true"
/>
<text-input v-else-if="!['files', 'signature'].includes(field.type)" name="prefill" class="mt-3"
:form="field"
label="Pre-filled value"
:disabled="field.type==='date' && field.prefill_today===true"