Skip to content

Commit

Permalink
fix file upload field
Browse files Browse the repository at this point in the history
  • Loading branch information
omohokcoj committed Nov 7, 2023
1 parent 3163cdc commit a42ae0b
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions app/javascript/submission_form/attachment_step.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<template>
<div>
<div v-if="modelValue.length">
<div v-if="value.length">
<div
v-for="(val, index) in modelValue"
v-for="(val, index) in value"
:key="index"
class="flex mb-2"
>
Expand All @@ -26,10 +26,7 @@
{{ attachmentsIndex[val].filename }}
</span>
</a>
<button
v-if="modelValue"
@click.prevent="removeAttachment(val)"
>
<button @click.prevent="removeAttachment(val)">
<IconTrashX
:width="18"
:heigh="19"
Expand Down Expand Up @@ -91,18 +88,28 @@ export default {
}
},
emits: ['attached', 'update:model-value'],
computed: {
value: {
set (value) {
this.$emit('update:model-value', this.modelValue || [])
},
get () {
return this.modelValue || []
}
}
},
methods: {
removeAttachment (uuid) {
this.modelValue.splice(this.modelValue.indexOf(uuid), 1)
this.value.splice(this.value.indexOf(uuid), 1)
this.$emit('update:model-value', this.modelValue)
this.$emit('update:model-value', this.value)
},
onUpload (attachments) {
attachments.forEach((attachment) => {
this.$emit('attached', attachment)
})
this.$emit('update:model-value', [...this.modelValue, ...attachments.map(a => a.uuid)])
this.$emit('update:model-value', [...this.value, ...attachments.map(a => a.uuid)])
}
}
}
Expand Down

0 comments on commit a42ae0b

Please sign in to comment.