Skip to content
Permalink
Browse files
fix: handle nested form options normalization (#5247)
  • Loading branch information
jacobmllr95 committed Apr 26, 2020
1 parent ee7e8b8 commit 0c57ffe31c946475498fa3554b8b4aba4e9d19df
Showing 2 changed files with 19 additions and 17 deletions.
@@ -1,5 +1,5 @@
import get from '../../../utils/get'
import { isArray, isPlainObject, isUndefined } from '../../../utils/inspect'
import { isNull, isPlainObject, isUndefined } from '../../../utils/inspect'
import formOptionsMixin from '../../../mixins/form-options'

// @vue/component
@@ -21,12 +21,12 @@ export default {
if (isPlainObject(option)) {
const value = get(option, this.valueField)
const text = get(option, this.textField)
const options = get(option, this.optionsField)
const options = get(option, this.optionsField, null)
// When it has options, create an `<optgroup>` object
if (isArray(options)) {
if (!isNull(options)) {
return {
label: String(get(option, this.labelField) || text),
options
options: this.normalizeOptions(options)
}
}
// Otherwise create an `<option>` object
@@ -33,19 +33,7 @@ export default {
},
computed: {
formOptions() {
const options = this.options
// Normalize the given options array
if (isArray(options)) {
return options.map(option => this.normalizeOption(option))
} else if (isPlainObject(options)) {
// Deprecate the object options format
warn(OPTIONS_OBJECT_DEPRECATED_MSG, this.$options.name)
// Normalize a `options` object to an array of options
return keys(options).map(key => this.normalizeOption(options[key] || {}, key))
}
// If not an array or object, return an empty array
/* istanbul ignore next */
return []
return this.normalizeOptions(this.options)
}
},
methods: {
@@ -67,6 +55,20 @@ export default {
text: stripTags(String(option)),
disabled: false
}
},
normalizeOptions(options) {
// Normalize the given options array
if (isArray(options)) {
return options.map(option => this.normalizeOption(option))
} else if (isPlainObject(options)) {
// Deprecate the object options format
warn(OPTIONS_OBJECT_DEPRECATED_MSG, this.$options.name)
// Normalize a `options` object to an array of options
return keys(options).map(key => this.normalizeOption(options[key] || {}, key))
}
// If not an array or object, return an empty array
/* istanbul ignore next */
return []
}
}
}

0 comments on commit 0c57ffe

Please sign in to comment.