Form Select

Bootstrap custom <select> using custom styles. Optionally specify options based on an array, array of objects, or an object.

Overview

Generate your select options by passing an array or object to the options props:

Selected:
HTML
vue
```vue
<template>
  <BFormSelect v-model="selected" :options="ex1Options" />

  <BFormSelect v-model="selected" :options="ex1Options" size="sm" class="mt-3" />

  <div class="mt-3">
    Selected: <strong>{{ selected }}</strong>
  </div>
</template>

<script setup lang="ts">
import {ref} from 'vue'

const ex1Options = [
  {value: null, text: 'Please select an option'},
  {value: 'a', text: 'This is First option'},
  {value: 'b', text: 'Selected Option'},
  {value: {C: '3PO'}, text: 'This is an option with object value'},
  {value: 'd', text: 'This one is disabled', disabled: true},
]

const selected = ref(null)
</script>

You can even define option groups with the options prop:

Selected:
HTML
vue
<template>
  <BFormSelect v-model="selected" :options="ex1GroupOptions" />

  <div class="mt-3">
    Selected: <strong>{{ selected }}</strong>
  </div>
</template>

<script setup lang="ts">
import {ref} from 'vue'

const ex1GroupOptions = [
  {value: null, text: 'Please select an option'},
  {value: 'a', text: 'This is First option'},
  {value: 'b', text: 'Selected Option', disabled: true},
  {
    label: 'Grouped options',
    options: [
      {value: {C: '3PO'}, text: 'Option with object value'},
      {value: {R: '2D2'}, text: 'Another option with object value'},
    ],
  },
]

const selected = ref()
</script>

Or manually provide your options and option groups:

Selected:
HTML
vue
<template>
  <BFormSelect v-model="selected">
    <BFormSelectOption :value="null">Please select an option</BFormSelectOption>
    <BFormSelectOption value="a">Option A</BFormSelectOption>
    <BFormSelectOption value="b" disabled>Option B (disabled)</BFormSelectOption>
    <BFormSelectOptionGroup label="Grouped options">
      <BFormSelectOption :value="{C: '3PO'}">Option with object value</BFormSelectOption>
      <BFormSelectOption :value="{R: '2D2'}">Another option with object value</BFormSelectOption>
    </BFormSelectOptionGroup>
  </BFormSelect>

  <div class="mt-3">
    Selected: <strong>{{ selected }}</strong>
  </div>
</template>

<script setup lang="ts">
import {ref} from 'vue'

const selected = ref(null)
</script>
Selected:
HTML
vue
<template>
  <BFormSelect v-model="selected" :options="exFirstSlotOptions" class="mb-3">
    <!-- This slot appears above the options from 'options' prop -->
    <template #first>
      <BFormSelectOption :value="null" disabled>-- Please select an option --</BFormSelectOption>
    </template>

    <!-- These options will appear after the ones from 'options' prop -->
    <BFormSelectOption value="C">Option C</BFormSelectOption>
    <BFormSelectOption value="D">Option D</BFormSelectOption>
  </BFormSelect>

  <div class="mt-3">
    Selected: <strong>{{ selected }}</strong>
  </div>
</template>

<script setup lang="ts">
import {ref} from 'vue'

const exFirstSlotOptions = [
  {value: 'A', text: 'Option A (from options prop)'},
  {value: 'B', text: 'Option B (from options prop)'},
]

const selected = ref(null)
</script>
ts
const options = ['A', 'B', 'C', {text: 'D', value: {d: 1}, disabled: true}, 'E', 'F']

If an array entry is a string, it will be used for both the generated value and text fields.

You can mix using strings and objects in the array.

Internally, BootstrapVueNext will convert the above array to the following array (the array of objects) format:

ts
const options = [
  {text: 'A', value: 'A', disabled: false},
  {text: 'B', value: 'B', disabled: false},
  {text: 'C', value: 'C', disabled: false},
  {text: 'D', value: {d: 1}, disabled: true},
  {text: 'E', value: 'E', disabled: false},
  {text: 'F', value: 'F', disabled: false},
]

Options as an array of objects

ts
const options = [
  {text: 'Item 1', value: 'first'},
  {text: 'Item 2', value: 'second'},
  {text: 'Item 3', value: 'third', disabled: true},
  {text: 'Item 4'},
  {text: 'Item 5', value: {foo: 'bar', baz: true}},
]

If value is missing, then text will be used as both the value and text fields.

Internally, BootstrapVueNext will convert the above array to the following array (the array of objects) format:

ts
const options = [
  {text: 'Item 1', value: 'first', disabled: false},
  {text: 'Item 2', value: 'second', disabled: false},
  {text: 'Item 3', value: 'third', disabled: true},
  {text: 'Item 4', value: 'Item 4', disabled: false},
  {text: 'Item 5', value: 'E', disabled: false},
]
Selected: A
HTML
vue
<template>
  <BFormSelect
    v-model="selected"
    :options="exFieldNamesOptions"
    class="mb-3"
    value-field="item"
    text-field="name"
    disabled-field="notEnabled"
  />

  <div class="mt-3">
    Selected: <strong>{{ selected }}</strong>
  </div>
</template>

<script setup lang="ts">
import {ref} from 'vue'

const exFieldNamesOptions = [
  {item: 'A', name: 'Option A'},
  {item: 'B', name: 'Option B'},
  {item: 'D', name: 'Option C', notEnabled: true},
  {item: {d: 1}, name: 'Option D'},
]

const selected = ref('A')
</script>

Options groups

To define option groups, just add an object with a label prop as the groups name and a options property with the array of options of the group.

ts
const options = [
  {text: 'Item 1', value: 'first'},
  {text: 'Item 2', value: 'second'},
  {
    label: 'Grouped options',
    options: [{text: 'Item< 3', value: 'third', disabled: true}, {text: 'Item 4'}],
  },
  {text: 'Item 5', value: {foo: 'bar', baz: true}},
]
Selected:
HTML
vue
<template>
  <BFormSelect v-model="selected" :options="ex1Options" />

  <div class="mt-3">
    Selected: <strong>{{ selected }}</strong>
  </div>
</template>

<script setup lang="ts">
import {ref} from 'vue'

const ex1Options = [
  {value: null, text: 'Please select an option'},
  {value: 'a', text: 'This is First option'},
  {value: 'b', text: 'Selected Option'},
  {value: {C: '3PO'}, text: 'This is an option with object value'},
  {value: 'd', text: 'This one is disabled', disabled: true},
]

const selected = ref()
</script>
Selected:
HTML
vue
<template>
  <BFormSelect v-model="selected" :options="ex1Options" :select-size="4" />

  <div class="mt-3">
    Selected: <strong>{{ selected }}</strong>
  </div>
</template>

<script setup lang="ts">
import {ref} from 'vue'

const ex1Options = [
  {value: null, text: 'Please select an option'},
  {value: 'a', text: 'This is First option'},
  {value: 'b', text: 'Selected Option'},
  {value: {C: '3PO'}, text: 'This is an option with object value'},
  {value: 'd', text: 'This one is disabled', disabled: true},
]

const selected = ref()
</script>
Selected: [ "b" ]
HTML
vue
<template>
  <BFormSelect v-model="selected" :options="exMultiOptions" multiple :select-size="4" />

  <div class="mt-3">
    Selected: <strong>{{ selected }}</strong>
  </div>
</template>

<script setup lang="ts">
import {ref} from 'vue'

const exMultiOptions = [
  {value: 'a', text: 'This is First option'},
  {value: 'b', text: 'Default Selected Option'},
  {value: 'c', text: 'This is another option'},
  {value: 'd', text: 'This one is disabled', disabled: true},
  {value: 'e', text: 'This is option e'},
  {value: 'f', text: 'This is option f'},
  {value: 'g', text: 'This is option g'},
]

const selected = ref(['b'])
</script>

Component Reference

<BFormSelect>

PropTypeDefaultDescription
aria-invalidAriaInvalidundefined Sets the `aria-invalid` attribute value on the wrapper element. When not provided, the `state` prop will control the attribute
autofocusbooleanfalse When set to `true`, attempts to auto-focus the control when it is mounted, or re-activated when in a keep-alive. Does not set the `autofocus` attribute on the control
disabledbooleanfalse When set to `true`, disables the component's functionality and places it in a disabled state
disabled-fieldstring'disabled' Field name in the `options` array that should be used for the disabled state
formstringundefined ID of the form that the form control belongs to. Sets the `form` attribute on the control
idstringundefined Used to set the `id` attribute on the rendered content, and used as the base to generate any additional element IDs as needed
label-fieldstring'label' The key to use from the option object to get the label
model-valueSelectValue'' The value of the select control
multiplebooleanfalse When set, allows multiple options to be selected (multi-select)
namestringundefined Sets the value of the `name` attribute on the form control
optionsunknown[] | Record<string, unknown>'() => []' Array of items to render in the component
options-fieldstring'options' The key to use from the option object to get the options
plainbooleanfalse Render the form control in plain mode, rather than custom styled mode
requiredbooleanundefined Adds the `required` attribute to the form control
select-sizeNumberish0 When set to a number larger than 0, will set the number of display option rows. Note not all browser will respect this setting
sizeSize'md' Set the size of the component's appearance. 'sm', 'md' (default), or 'lg'
stateValidationStateundefined Controls the validation state appearance of the component. `true` for valid, `false` for invalid, or `null` for no validation state
text-fieldstring'text' Field name in the `options` array that should be used for the text label
value-fieldstring'value' Field name in the `options` array that should be used for the value
EventArgsDescription
update:model-value
value: SelectValue - Currently selected value of the select control.
Emitted when the selected value(s) are changed. Looking for the `input` or `change` event - use `update:model-value` instead.
NameScopeDescription
defaultContent to place in the form select
firstSlot to place options or option groups above options provided via the 'options' prop
option
value: any (T) - The value of the option
text: string - The text of the option
disabled: boolean - Is the option disabled
Use this slot to have finer control over the content render inside each select item

<BFormSelectOption>

PropTypeDefaultDescription
disabledbooleanfalse The disabled state of the option
valueanyundefined The value of the option
NameScopeDescription
defaultContent to place in the form select option

<BFormSelectOptionGroup>

PropTypeDefaultDescription
disabled-fieldstring'disabled' Field name in the `options` array that should be used for the disabled state
labelstringundefined The label for the option group
optionsreadonly (unknown | Record<string, unknown>)[]'() => []' Array of items to render in the component
text-fieldstring'text' Field name in the `options` array that should be used for the text label
value-fieldstring'value' Field name in the `options` array that should be used for the value
NameScopeDescription
defaultSlot to place options above options provided via the 'options' prop
firstContent to place in the form select option group
option
value: any (T) - The value of the option
text: string - The text of the option
disabled: boolean - Is the option disabled
Use this slot to have finer control over the content render inside each select item