Skip to content

Commit

Permalink
fix(b-form-file): fix value prop validation when using directory mode (
Browse files Browse the repository at this point in the history
…fixes #4912) (#4913)

* fix(b-form-file): fix value prop validation when using directory mode


Fixes #4912

* Update form-file.js

* Update form-file.js

* Update form-file.js

* Update form-file.js

* Update form-file.js

* Update form-file.js

* Update form-file.js

Co-authored-by: Jacob Müller <jacob.mueller.elz@gmail.com>
  • Loading branch information
tmorehouse and jacobmllr95 authored Mar 9, 2020
1 parent d567ceb commit 498a262
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/components/form-file/form-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ import formStateMixin from '../../mixins/form-state'
import idMixin from '../../mixins/id'
import normalizeSlotMixin from '../../mixins/normalize-slot'

// --- Constants ---

const NAME = 'BFormFile'

const VALUE_EMPTY_DEPRECATED_MSG =
'Setting "value"/"v-model" to an empty string for reset is deprecated. Set to "null" instead.'

// --- Helper methods ---

const isValidValue = value => isFile(value) || (isArray(value) && value.every(v => isValidValue(v)))

// @vue/component
export const BFormFile = /*#__PURE__*/ Vue.extend({
name: NAME,
Expand All @@ -34,17 +40,13 @@ export const BFormFile = /*#__PURE__*/ Vue.extend({
value: {
type: [File, Array],
default: null,
validator: val => {
validator: value => {
/* istanbul ignore next */
if (val === '') {
if (value === '') {
warn(VALUE_EMPTY_DEPRECATED_MSG, NAME)
return true
}
return (
isUndefinedOrNull(val) ||
isFile(val) ||
(isArray(val) && (val.length === 0 || val.every(isFile)))
)
return isUndefinedOrNull(value) || isValidValue(value)
}
},
accept: {
Expand Down

0 comments on commit 498a262

Please sign in to comment.