85

I read on many forums that the problem of select and multiselect has been resolved after the beta version of bootstrap 4.

Unfortunately I am unable to display the multiselect as in (bootstrap 3) in (bootstrap 4).

Bootstrap 3 Snippet

$('select').selectpicker();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.8.1/css/bootstrap-select.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.8.1/js/bootstrap-select.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>

<select class="selectpicker" multiple data-live-search="true">
  <option>Mustard</option>
  <option>Ketchup</option>
  <option>Relish</option>
</select>

Bootstrap 4 Snippet

$('select').selectpicker();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.bundle.min.js"></script>

<select class="selectpicker" multiple data-live-search="true">
  <option>Mustard</option>
  <option>Ketchup</option>
  <option>Relish</option>
</select>
dippas
  • 58,591
  • 15
  • 114
  • 126
Kees de Jager
  • 582
  • 1
  • 7
  • 25

1 Answers1

145

Because the bootstrap-select is a Bootstrap component and therefore you need to include it in your code as you did for your V3

NOTE: this component only works in since version 1.13.0

$('select').selectpicker();
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.1/css/bootstrap-select.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.bundle.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.1/js/bootstrap-select.min.js"></script>

<select class="selectpicker" multiple data-live-search="true">
  <option>Mustard</option>
  <option>Ketchup</option>
  <option>Relish</option>
</select>
dippas
  • 58,591
  • 15
  • 114
  • 126
  • 2
    Updated bootstrap-select website: https://developer.snapappointments.com/bootstrap-select/ and github repository: https://github.com/snapappointments/bootstrap-select/ in order to find the latest 1.13+ versions of the plugin which work with bootstrap 4. – Brice Roncace Jul 17 '18 at 15:05
  • 1
    @dippas selectpicker is working as expected, I need to have select "ALL" option as well. Can you help how can i do this?. Thanks in Advance – RakeshKalwa Sep 18 '18 at 11:52
  • 7
    @RakeshKalwa Not sure if you still need it but you can select all options with `$('.selectpicker').selectpicker('selectAll');` and deselect all options with `$('.selectpicker').selectpicker('deselectAll');`. – Stefan Teunissen Apr 24 '19 at 11:10
  • 1
    How do you preselect it, in case of edit functionality ? Like once selected, and when i come back to edit it, i need to show last selected values. – Hemant Nagpal Jul 24 '19 at 06:44
  • 1
    Try this bootstrap multiselect dropdown - https://bbbootstrap.com/snippets/multiselect-dropdown-list-83601849 – Upasana Chauhan Sep 27 '19 at 14:16
  • To post all your selections, you also need to set the select name as an array: – Carl May 04 '20 at 20:38
  • 2
    Ho can I add values dynamically from server side to this drop down box. – Dnyati Jan 18 '22 at 03:36
  • would it work the same as a `dropdownlist` in asp.net mvc? – Luis Feb 16 '23 at 16:57
  • Can we add 'grouped' options to this ? – UI_Brain Jun 01 '23 at 15:05
  • @Dnyati you after you dynamically update: $('select').selectpicker("refresh"); – SaintFrag Jun 26 '23 at 19:33