File tree 5 files changed +24
-7
lines changed
5 files changed +24
-7
lines changed Original file line number Diff line number Diff line change @@ -253,7 +253,7 @@ assistive technologies.
253
253
254
254
With inputs of type file, normally the ` v-model ` is uni-directional (meaning you cannot pre-set the
255
255
selected files). However, you can clear the file input's selected files by setting the ` v-model ` to
256
- either ` null ` , an empty string ` '' ` , or an empty array ` [] ` ).
256
+ either ` null ` (for single mode) or an empty array ` [] ` (for multiple/directory mode ).
257
257
258
258
Alternatively, ` <b-form-file> ` provides a ` reset() ` method that can be called to clear the file
259
259
input. To take advantage of the ` reset() ` method, you will need to obtain a reference to the
Original file line number Diff line number Diff line change 1
1
import Vue from '../../utils/vue'
2
2
import { from as arrayFrom , isArray , concat } from '../../utils/array'
3
3
import { getComponentConfig } from '../../utils/config'
4
- import { isFunction } from '../../utils/inspect'
4
+ import { isFile , isFunction , isUndefinedOrNull } from '../../utils/inspect'
5
5
import { File } from '../../utils/safe-types'
6
+ import { warn } from '../../utils/warn'
6
7
import formCustomMixin from '../../mixins/form-custom'
7
8
import formMixin from '../../mixins/form'
8
9
import formStateMixin from '../../mixins/form-state'
@@ -27,7 +28,21 @@ export const BFormFile = /*#__PURE__*/ Vue.extend({
27
28
} ,
28
29
value : {
29
30
type : [ File , Array ] ,
30
- default : null
31
+ default : null ,
32
+ validator : val => {
33
+ /* istanbul ignore next */
34
+ if ( val === '' ) {
35
+ warn (
36
+ `${ NAME } - setting value/v-model to an empty string for reset is deprecated. Set to 'null' instead`
37
+ )
38
+ return true
39
+ }
40
+ return (
41
+ isUndefinedOrNull ( val ) ||
42
+ isFile ( val ) ||
43
+ ( isArray ( val ) && ( val . length === 0 || val . every ( isFile ) ) )
44
+ )
45
+ }
31
46
} ,
32
47
accept : {
33
48
type : String ,
Original file line number Diff line number Diff line change @@ -340,7 +340,7 @@ describe('form-file', () => {
340
340
const wrapper = mount ( BFormFile , {
341
341
propsData : {
342
342
id : 'foo' ,
343
- value : ''
343
+ value : null
344
344
}
345
345
} )
346
346
const file1 = new File ( [ 'foo' ] , 'foo.txt' , {
@@ -358,8 +358,7 @@ describe('form-file', () => {
358
358
wrapper . setProps ( { value : null } )
359
359
await waitNT ( wrapper . vm )
360
360
361
- expect ( wrapper . emitted ( 'input' ) . length ) . toEqual ( 2 )
362
- expect ( wrapper . emitted ( 'input' ) [ 1 ] [ 0 ] ) . toEqual ( null )
361
+ expect ( wrapper . emitted ( 'input' ) . length ) . toEqual ( 1 )
363
362
364
363
wrapper . destroy ( )
365
364
} )
Original file line number Diff line number Diff line change 13
13
"props" : [
14
14
{
15
15
"prop" : " value" ,
16
- "description" : " The current value of the file input. Will be an array if multiple or directory is set. Can be set to null or empty array to reset the file input"
16
+ "description" : " The current value of the file input. Will be a single File object or an array of File objects ( if multiple or directory is set) . Can be set to null, or an empty array to reset the file input"
17
17
},
18
18
{
19
19
"prop" : " accept" ,
Original file line number Diff line number Diff line change 1
1
import { isArray } from './array'
2
2
import { isObject , isPlainObject } from './object'
3
+ import { File } from './safe-types'
3
4
4
5
// --- Convenience inspection utilities ---
5
6
@@ -29,6 +30,8 @@ export const isDate = val => val instanceof Date
29
30
30
31
export const isEvent = val => val instanceof Event
31
32
33
+ export const isFile = val => val instanceof File
34
+
32
35
export const isRegExp = val => toRawType ( val ) === 'RegExp'
33
36
34
37
export const isPromise = val =>
You can’t perform that action at this time.
0 commit comments