Skip to content

Commit aee91ce

Browse files
committed
feat(QFile): New Boolean prop --> append quasarframework#6955
1 parent f9d91ab commit aee91ce

File tree

5 files changed

+58
-3
lines changed

5 files changed

+58
-3
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<template>
2+
<div class="q-pa-md">
3+
<q-file
4+
v-model="files"
5+
label="Pick files"
6+
filled
7+
multiple
8+
append
9+
style="max-width: 300px"
10+
/>
11+
</div>
12+
</template>
13+
14+
<script>
15+
export default {
16+
data () {
17+
return {
18+
files: null
19+
}
20+
}
21+
}
22+
</script>

docs/src/pages/vue-components/file-picker.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ Under the covers, QFile uses a native input. Due to browser security policy, it
5353

5454
<doc-example title="Multiple files" file="QFile/BasicMultiple" />
5555

56+
### Appending files <q-badge align="top" label="v1.11.3+" />
57+
58+
By default, QFile replaces the model each time the user selects any files through the popup. However, when you are accepting multiple files (`multiple` prop) you can change this behavior and append the new selection to the model rather than replacing its old value.
59+
60+
Below you can pick files multiple times and QFile will keep on appending them to the model:
61+
62+
<doc-example title="Appending files" file="QFile/AppendingFiles" />
63+
5664
### Counters
5765

5866
<doc-example title="Basic counter" file="QFile/CounterBasic" />

ui/dev/src/pages/form/file-picker.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@
1818

1919
<q-btn type="submit" label="Submit" />
2020
</form>
21+
22+
<div class="q-mt-md">
23+
<q-file name="file1" filled v-model="multiAppend" label="Mutiple & Append" clearable multiple append />
24+
</div>
2125
</div>
2226
</template>
2327

2428
<script>
2529
export default {
2630
data () {
2731
return {
32+
multiAppend: null,
2833
fileS: null,
2934
fileM: null,
3035

ui/src/components/file/QFile.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default Vue.extend({
2121
? {}
2222
: [ File, FileList, Array ],
2323

24+
append: Boolean,
2425
useChips: Boolean,
2526
displayValue: [ String, Number ],
2627

@@ -88,6 +89,10 @@ export default Vue.extend({
8889
id: this.targetUid,
8990
disabled: this.editable !== true
9091
}
92+
},
93+
94+
isAppending () {
95+
return this.multiple === true && this.append === true
9196
}
9297
},
9398

@@ -119,8 +124,13 @@ export default Vue.extend({
119124
},
120125

121126
__addFiles (e, fileList) {
122-
const files = this.__processFiles(e, fileList)
123-
files !== void 0 && this.__emitValue(files)
127+
const files = this.__processFiles(e, fileList, this.innerValue, this.isAppending)
128+
129+
files !== void 0 && this.__emitValue(
130+
this.isAppending === true
131+
? this.innerValue.concat(files)
132+
: files
133+
)
124134
},
125135

126136
__getControl (h) {
@@ -211,6 +221,9 @@ export default Vue.extend({
211221

212222
created () {
213223
this.fieldClass = 'q-file q-field--auto-height'
214-
this.type = 'file' // necessary for QField's clearable
224+
225+
// necessary for QField's clearable
226+
// and FileValueMixin
227+
this.type = 'file'
215228
}
216229
})

ui/src/components/file/QFile.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
"category": "model"
1515
},
1616

17+
"append": {
18+
"type": "Boolean",
19+
"desc": "Append file(s) to current model rather than replacing them; Has effect only when using 'multiple' mode",
20+
"category": "behavior",
21+
"addedIn": "v1.11.3"
22+
},
23+
1724
"display-value": {
1825
"type": [ "Number", "String" ],
1926
"desc": "Override default selection string, if not using 'file' or 'selected' scoped slots and if not using 'use-chips' prop",

0 commit comments

Comments
 (0)