bootstrap-multiselect icon indicating copy to clipboard operation
bootstrap-multiselect copied to clipboard

Compatibility with Bootstrap 5

Open tasam21 opened this issue 3 years ago • 18 comments

First of all I would like to say thank you for your bootstrap-multiselect components. I have used this bootstrap component in one of my project. Since, I upgraded my project with the latest version of Bootstrap i.e. Bootstrap 5 beta2 As we all know Bootstrap 5 no longer depends on jQuery. Therefore, do you have any plan in upgrading this component to make it compatible with BS5 ? Thanks.

tasam21 avatar Mar 09 '21 15:03 tasam21

While Bootstrap 5 doesn't depend on jQuery, it does support it: https://getbootstrap.com/docs/5.0/getting-started/javascript/#still-want-to-use-jquery-its-possible

So aside from any required markup changes, it should still work.

tiesont avatar Mar 09 '21 20:03 tiesont

Does anyone know which tags need to be changed? I'm using v5.0.0-beta3 and I've been looking for a fix. The dropdown is different from v4. Thank you!

shinyat avatar Apr 18 '21 18:04 shinyat

A little progress. I installed popper.js and changed the following lines in the js.

line 410 div class="dropdown" line 450 data-bs-toggle="dropdown"

Not sure if this is fully functioning, but I can see the dropdown popup at least. I'll test furthermore.

shinyat avatar Apr 18 '21 19:04 shinyat

I'd do a PR right now if there was an easy way to catch the Bootstrap version at init and modify Multiselect.defaults.templates.button and Multiselect.defaults.templates.buttonContainer on the fly.

Previously we were able to use $.fn.tooltip.Constructor.VERSION as a hack with some reliability, but since jQuery is now optional, this solution isn't universal.

Silly as it might be, this tiny markup change might require a major version bump for this plugin that is not backwards compatible.

evansharp avatar May 04 '21 05:05 evansharp

Any ideas @tiesont ?

evansharp avatar May 10 '21 02:05 evansharp

@evansharp Well, we could just emit both versions of Bootstrap's data attributes, although that seems like we'd be polluting the markup (every attribute would basically be duplicated).

Seems like we should be to just detect if jQuery (or Zepto, or any other library offering the same API) is present, and just use the VERSION property like you mentioned.

I haven't looked at Bootstrap 5 in a while. I'll do that and see if I can come up with a better polyfill.

tiesont avatar May 10 '21 03:05 tiesont

@tasam21, what I did on my side: in bootstrap-multiselect.js

line 407: change buttonClass: 'custom-select', into: buttonClass: 'form-select', line 450: change data-toggle="dropdown" into: data-bs-toggle="dropdown"

and it seems working fine with bootstrap 5.0.2

halimus avatar Jul 03 '21 18:07 halimus

@tasam21, what I did on my side: in bootstrap-multiselect.js

line 407: change buttonClass: 'custom-select', into: buttonClass: 'form-select', line 450: change data-toggle="dropdown" into: data-bs-toggle="dropdown"

and it seems working fine with bootstrap 5.0.2

Thanks so much. It works for me as well.

roomoraaes avatar Jul 21 '21 14:07 roomoraaes

@halimus thank you for sharing your tips. I'm no more using bootstrap-multiselect for my project. It's replaced with vue-multiselect https://vue-multiselect.js.org/

tasamphel avatar Jul 21 '21 15:07 tasamphel

Is it any updates on this task? Unfortunately @halimus solution does not work anymore :(

gidroponik54 avatar Sep 10 '21 21:09 gidroponik54

Same here. Bootstrap v3.3.7 works but not on 5.0.2 nor 4.0

Adi-18 avatar Sep 29 '21 07:09 Adi-18

You can do this, Workaround on bootstrap v5.1 or higher.

$('#example').multiselect({
    buttonClass: 'form-select',
    templates: {
        button: '<button type="button" class="multiselect dropdown-toggle" data-bs-toggle="dropdown"><span class="multiselect-selected-text"></span></button>',
    }
});

krit0627 avatar Nov 24 '21 04:11 krit0627

@krit0627 Thanks You saved my day.

dhsont avatar Dec 22 '21 17:12 dhsont

if (window.bootstrap && window.bootstrap.Alert.VERSION.startsWith('5'))
$.fn.multiselect.Constructor.prototype.defaults.templates.button = '<button type="button" class="multiselect dropdown-toggle form-control" data-bs-toggle="dropdown"><span class="multiselect-selected-text"></span></button>'

gh-at-sqh avatar Mar 12 '22 09:03 gh-at-sqh

Also see #1226.

davidstutz avatar Jul 09 '22 23:07 davidstutz

Thanks all for the Bootstrap 5 workaround. The major functionality seems to work. However, FYI, I couldn't get includeResetOption working, and I presume it's a Bootstrap 5 incompatibility.

iainteractive-iain avatar Jul 28 '22 16:07 iainteractive-iain

I have made the templates change which fixed most of my issues, but I am having issues with the Select All appearing in all my multiselect dropdowns. It seems that if the dropdown is all unselected it appears, but for SOME, not all, dropdowns if all the options are selected the Select All option is not showing. I can't remember if this worked in bootstrap 3.3.7 or not. I will create a new issue, but wanted to add it here if it is a bootstrap 5 related issue.

bobhelwig avatar Aug 12 '22 12:08 bobhelwig

Would it be possible to support bootstrap 4 and 5 separately like it is done in datatables? I mean, distribute multiple CSS and JS files depending on the Bootstrap version. Another example: selectize.js

bedroesb avatar Aug 12 '22 12:08 bedroesb