Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/components/form-select/helpers/mixin-options.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
28 changes: 15 additions & 13 deletions src/mixins/form-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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 []
}
}
}