Skip to content

Latest commit

 

History

History
21 lines (15 loc) · 2.45 KB

File metadata and controls

21 lines (15 loc) · 2.45 KB

Bootstrap Multiselect - Show Selected

Small plugin for showing the selected values first as an optgroup when opening a bootstrap-multiselect dropdown. Please be aware that the selected values list only updates when the dropdown is opened.

Example of multiselect showing the selected values.

In order to use it, simply load the JavaScript and CSS files after bootstrap-multiselect. Then you can specify the following new options when initializing the bootstrap-multiselect component:

  • showSelectedValues: whether we want to show the currently selected values upon opening the dropdown. Setting it to false completely disables this plugin. Default: false
  • showSelectedValuesCollapsed: whether we want the currently selected values optgroup to show initially collapsed when opening the dropdown. Default: false
  • showSelectedValuesOnlyOnce: whether we want the currently selected values to be shown only in the selected values optgroup, hiding them from their usual place in the list below. Default: false
  • showSelectedValuesEmpty: whether we want the currently selected values optgroup to be shown when there are no values selected, displaying the text specified with the parameter selectedValuesNoValuesText. Default: true
  • selectedValuesTitleText: the text we want to show as title of the selected values optgroup. Default: "Values initially selected"
  • selectedValuesNoValuesText: the text we want to show inside the selected values optgroup when there are no values selected. Default: "None"

Additional notes:

  • I'm aware that the code is quite inelegant, just wanted a quick fix for my project needs.
  • The original value checkbox and the one shown in the new selected values optgroup are always synced, but this is done in an unoptimized way by just refreshing all the checkboxes with each change. Shouldn't be a problem in most cases, but if you have thousands of items, then it could be.
  • If you use the option showSelectedValuesOnlyOnce, optgroups with all their options selected will still be shown empty in the list below.
  • Has been tested to work with most bootstrap-multiselect options in version 1.0.0, at least up to commit e15132b. Can't guarantee it to work with older or newer versions.