Skip to content

Commit

Permalink
fix: when the Field type is "file", value can not be updated (#2452)
Browse files Browse the repository at this point in the history
* fix: when the Field type is file value can not be updated

* update code style
  • Loading branch information
kopinions authored and erikras committed Jan 25, 2017
1 parent 29d3495 commit 86c64fe
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"rifraf": "^2.0.3",
"rimraf": "^2.5.4",
"stringstream": "^0.0.5",
"tmp": "0.0.31",
"webpack": "^1.14.0"
},
"peerDependencies": {
Expand Down
11 changes: 11 additions & 0 deletions src/__tests__/createFieldProps.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import plainExpectations from '../structure/plain/expectations'
import immutable from '../structure/immutable'
import immutableExpectations from '../structure/immutable/expectations'
import addExpectations from './addExpectations'
import tmp from 'tmp'

const describeCreateFieldProps = (name, structure, expect) => {
const { empty, getIn, fromJS, toJS } = structure
Expand Down Expand Up @@ -334,6 +335,16 @@ const describeCreateFieldProps = (name, structure, expect) => {
.toEqual(undefined)
})

it('should update value to selected file for file inputs', () => {
let tmpFile = tmp.fileSync()
expect(createFieldProps({ getIn, toJS }, 'foo', {
value: [ tmpFile ],
state: empty,
type: 'file'
}).input.value)
.toEqual([ tmpFile ])
})

it('should replace undefined value with empty string', () => {
const result = createFieldProps({ getIn, toJS }, 'foo', {
state: empty
Expand Down
2 changes: 1 addition & 1 deletion src/createFieldProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const processProps = (type, props, _value) => {
if (type === 'file') {
return {
...props,
value: undefined
value: value || undefined
}
}
return props
Expand Down

0 comments on commit 86c64fe

Please sign in to comment.