[enh] Be able to delete source file

This commit is contained in:
ljf 2021-08-31 04:21:10 +02:00
parent 358e6978a4
commit 5e554bb4a2
4 changed files with 30 additions and 11 deletions

View file

@ -1,15 +1,15 @@
<template>
<b-button-group class="w-100">
<b-button @click="clearFiles" variant="danger" v-if="!required && file">
<b-button @click="clearFiles" variant="danger" v-if="!this.required && this.value !== null && !this.value._removed">
<icon iname="trash" />
</b-button>
<b-form-file
v-model="file"
ref="file-input"
ref="input-file"
:id="id"
:required="required"
v-on="$listeners"
:placeholder="placeholder_"
:required="required"
:placeholder="_placeholder"
:accept="accept"
@blur="$parent.$emit('touch', name)"
/>
@ -22,8 +22,7 @@ export default {
data () {
return {
file: this.value,
placeholder_: (this.value) ? this.value.name : this.placeholder
file: this.value
}
},
@ -36,12 +35,24 @@ export default {
name: { type: String, default: null }
},
computed: {
_placeholder: function () {
return (this.value === null) ? this.placeholder : this.value.name
}
},
methods: {
clearFiles () {
this.file = null
this.placeholder_ = this.placeholder
this.$refs['file-input'].reset()
const f = new File([''], this.placeholder)
f._removed = true
if (this.value && this.value.currentfile) {
this.$refs['input-file'].reset()
this.$emit('input', f)
} else {
this.$refs['input-file'].setFiles([f])
this.file = f
this.$emit('input', f)
}
}
}
}

View file

@ -10,7 +10,7 @@ export default {
name: 'ReadOnlyAlertItem',
data () {
let icons = {
const icons = {
success: 'thumbs-up',
info: 'info',
warning: 'warning',

View file

@ -130,7 +130,8 @@ export function formatYunoHostArgument (arg) {
props: defaultProps.concat(['accept']),
callback: function () {
if (value) {
value = new File([''], value.replace(/^.*[/]/, ''))
value = new File([''], value)
value.currentfile = true
}
}
},
@ -337,6 +338,12 @@ export async function formatFormData (
} else if (removeNull && (value === null || value === undefined)) {
continue
} else if (value instanceof File) {
if (value.currentfile) {
continue
} else if (value._removed) {
output[type][key] = ''
continue
}
promises.push(pFileReader(value, output[type], key))
} else if (flatten && isObjectLiteral(value)) {
flattenObjectLiteral(value, output[type])

View file

@ -110,6 +110,7 @@ export default {
},
applyConfig (id_) {
console.debug(this.forms[id_])
formatFormData(this.forms[id_], { promise: true, removeEmpty: false, removeNull: true }).then((formatedData) => {
console.debug(formatedData)
const args = objectToParams(formatedData)