bootstrap-vue
Version:
BootstrapVue, with more than 85 custom components, over 45 plugins, several custom directives, and over 300 icons, provides one of the most comprehensive implementations of Bootstrap v4 components and grid system for Vue.js. With extensive and automated W
49 lines (47 loc) • 1.44 kB
JavaScript
import get from '../../../utils/get'
import { isNull, isPlainObject, isUndefined } from '../../../utils/inspect'
import formOptionsMixin from '../../../mixins/form-options'
// @vue/component
export default {
mixins: [formOptionsMixin],
props: {
labelField: {
type: String,
default: 'label'
},
optionsField: {
type: String,
default: 'options'
}
},
methods: {
normalizeOption(option, key = null) {
// When the option is an object, normalize it
if (isPlainObject(option)) {
const value = get(option, this.valueField)
const text = get(option, this.textField)
const options = get(option, this.optionsField, null)
// When it has options, create an `<optgroup>` object
if (!isNull(options)) {
return {
label: String(get(option, this.labelField) || text),
options: this.normalizeOptions(options)
}
}
// Otherwise create an `<option>` object
return {
value: isUndefined(value) ? key || text : value,
text: String(isUndefined(text) ? key : text),
html: get(option, this.htmlField),
disabled: Boolean(get(option, this.disabledField))
}
}
// Otherwise create an `<option>` object from the given value
return {
value: key || option,
text: String(option),
disabled: false
}
}
}
}