Skip to main content
Version: 1.2

Events

bootstrap-select emits native CustomEvents on the original <select> element.

Listening for events

const select = document.querySelector('#mySelect');

select.addEventListener('changed.bs.select', function (e) {
const { clickedIndex, isSelected, previousValue } = e.detail;
console.log('selection changed', { clickedIndex, isSelected, previousValue });
});

select.addEventListener('show.bs.select', function (e) {
const bootstrapEvent = e.detail.bsEvent;
const button = bootstrapEvent.relatedTarget;
console.log('opening from button', button);
});

Event detail

  • show.bs.select, shown.bs.select, hide.bs.select, and hidden.bs.select expose the original Bootstrap dropdown event as event.detail.bsEvent.
  • changed.bs.select exposes clickedIndex, isSelected, and previousValue on event.detail.
  • If the value changed via val(), selectAll(), or deselectAll(), clickedIndex and isSelected are null.

Event reference

Event typeDescription
show.bs.selectFires immediately when the menu starts opening.
shown.bs.selectFires after the menu is visible to the user.
hide.bs.selectFires immediately when the menu starts closing.
hidden.bs.selectFires after the menu has finished closing.
loaded.bs.selectFires after the selectpicker has been initialized.
rendered.bs.selectFires after render() updates the UI.
refreshed.bs.selectFires after refresh() syncs the UI with the underlying <select>.
changed.bs.selectFires after the value changes. event.detail contains clickedIndex, isSelected, and previousValue.
maxReached.bs.selectFires when a multi-select exceeds the configured maxOptions limit.
maxReachedGrp.bs.selectFires when an <optgroup> exceeds its configured data-max-options limit.
fetched.bs.selectFires after async or callback-backed source data has been fetched and applied.