$('#select2-input').on('change', function () { // show toast notification to user });
All Select2 Events
Below are the available events that select2 provides and for each of these events you can listen and perform your action.
- change - Triggered whenever an option is selected or removed.
- change.select2 - Scoped version of change. See below for more details.
- select2:closing - Triggered before the dropdown is closed. This event can be prevented.
- select2:close - Triggered whenever the dropdown is closed. select2:closing is fired before this and can be prevented.
- select2:opening - Triggered before the dropdown is opened. This event can be prevented.
- select2:open - Triggered whenever the dropdown is opened. select2:opening is fired before this and can be prevented.
- select2:selecting - Triggered before a result is selected. This event can be prevented.
- select2:select - Triggered whenever a result is selected. select2:selecting is fired before this and can be prevented.
- select2:unselecting - Triggered before a selection is removed. This event can be prevented.
- select2:unselect - Triggered whenever a selection is removed. select2:unselecting is fired before this and can be prevented.
- select2:clearing - Triggered before all selections are cleared. This event can be prevented.
- select2:clear - Triggered whenever all selections are cleared. select2:clearing is fired before this and can be prevented.
$('#select2-input').on('select2:clear', function (e) { // call ajax here });
$('#select2-input').on('select2:select', function (e) { console.log(e.params.data) // filters.selectedReportType });
Leave a reply