Skip to content

Commit a979d40

Browse files
committed
[2.7.6] Pass fileList prop as file-list prop to <Upload />
1 parent a1350ad commit a979d40

File tree

4 files changed

+40
-8
lines changed

4 files changed

+40
-8
lines changed

CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
## 2.7.6
2+
3+
### Fixed
4+
5+
— Pass `fileList` prop as `file-list` prop to `<Upload />`
6+
— Can't use value for now as `file-list` prop
7+
8+
```js
9+
// Correct example
10+
<Upload
11+
formItem
12+
showFileList
13+
name="specificationFiles"
14+
label="Upload Specification*"
15+
labelWidth="150px"
16+
endpoint="uploadSpecification"
17+
// These initial values you have passed to form
18+
// Default value is an empty array
19+
fileList={this.initialValues.specificationFiles}
20+
httpRequest={this.createUploadFile}
21+
formatResponse={this.formatResponse}>
22+
<Button>Browse</Button>
23+
</Upload>
24+
```
25+
126
## 2.7.5
227

328
### Fixed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ See demo at [https://detools.github.io/vue-form](https://detools.github.io/vue-f
8080

8181
## Changelog
8282

83+
- [2.7.6](/CHANGELOG.md#276)
8384
- [2.7.5](/CHANGELOG.md#275)
8485
- [2.7.4](/CHANGELOG.md#274)
8586
- [2.7.3](/CHANGELOG.md#273)

VueForm/components/ConnectedUpload.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Upload } from 'element-ui'
22
import noop from 'lodash/noop'
3+
import castArray from 'lodash/castArray'
34
import ConnectedControlMixin from '../mixins/ConnectedControl'
45

56
const defaultHandler = {
@@ -82,10 +83,10 @@ const ConnectedInput = {
8283
default: response => response,
8384
},
8485

85-
// fileList: {
86-
// type: Array,
87-
// default: () => [],
88-
// },
86+
fileList: {
87+
type: Array,
88+
default: () => [],
89+
},
8990

9091
listType: {
9192
type: String,
@@ -158,10 +159,15 @@ const ConnectedInput = {
158159
this.handleSuccess(response, file, filelist)
159160

160161
const [, setValue] = this.state
161-
setValue(this.formatResponse(response, file, filelist))
162+
const transformedResponse = this.formatResponse(response, file, filelist)
163+
const nextValue = castArray(filelist)
164+
.slice(0, -1)
165+
.concat(transformedResponse)
166+
167+
setValue(nextValue)
162168
},
163169

164-
renderComponent(value) {
170+
renderComponent() {
165171
return (
166172
<Upload
167173
{...this.callbacks}
@@ -177,7 +183,7 @@ const ConnectedInput = {
177183
accept={this.accept}
178184
before-upload={this.beforeUpload}
179185
before-remove={this.beforeRemove}
180-
file-list={value}
186+
file-list={this.fileList}
181187
list-type={this.listType}
182188
auto-upload={this.autoUpload}
183189
http-request={this.httpRequest}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@detools/vue-form",
3-
"version": "2.7.5",
3+
"version": "2.7.6",
44
"description": "Form State Management for VueJS",
55
"main": "VueForm/index.js",
66
"scripts": {

0 commit comments

Comments
 (0)