Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrap 5 support #2505

Closed
pchaganti opened this issue Jul 24, 2020 · 60 comments
Closed

Bootstrap 5 support #2505

pchaganti opened this issue Jul 24, 2020 · 60 comments
Labels
Milestone

Comments

@pchaganti
Copy link

Trying to instantiate a new bootstrap select when using BS5 gives this error. I realize BS5 is still alpha but this is something to keep an eye on. Hopefully it is a simple fix in the constructor.

TypeError: undefined is not an object (evaluating 'C.dropdown._menu=C.$menu[0]')

thanks

@pchaganti pchaganti added the bug label Jul 24, 2020
@caseyjhol
Copy link
Member

caseyjhol commented Jul 24, 2020

Looks like this has to do with Bootstrap 5 dropping jQuery, so some of the variables/methods will have to be accessed differently.

https://plnkr.co/edit/w2MkWyZCEoa4KJ3W

@AnnoyingTechnology
Copy link

@caseyjhol are there any plans to support Bootstrap 5 ?

@AnnoyingTechnology
Copy link

I definitely want to support Bootstrap 5 and offer a version without jQuery as a dependency. I've already begun removing jQuery code and replacing it with native JS where possible. It'll be much easier to support/maintain once IE < 11 support is dropped, since we won't be as limited and will be able to remove most of the polyfills. I'm thinking that might be a more realistic goal for bootstrap-select v3.0.0, though.

Originally posted by @caseyjhol in #2228 (comment)

@caseyjhol caseyjhol added this to the v2.0.0 milestone Dec 2, 2020
@caseyjhol caseyjhol pinned this issue Dec 2, 2020
@caseyjhol caseyjhol changed the title Bootstrap5 error Bootstrap 5 support Dec 2, 2020
@caseyjhol
Copy link
Member

Making this the thread to discuss Bootstrap 5 support.

@ghost
Copy link

ghost commented Dec 10, 2020

Do you plan add suopport bootstrap 5?

@AnnoyingTechnology
Copy link

AnnoyingTechnology commented Dec 10, 2020

Please do not spam the maintainer.
It's better practice to react to the original question (thumbs) if you want to manifest an interest.

Screenshot from 2020-12-23 12-07-42

@ldcxtu
Copy link

ldcxtu commented Dec 23, 2020

bootstrap 5 needs you

@ldcxtu
Copy link

ldcxtu commented Dec 27, 2020

There was an issue retrieving Bootstrap's version. Ensure Bootstrap is being loaded before bootstrap-select and there is no namespace collision. If loading Bootstrap asynchronously, the version may need to be manually specified via $.fn.selectpicker.Constructor.BootstrapVersion. TypeError: Cannot read property 'Constructor' of undefined
at S.fn.init.Plugin [as selectpicker] (bootstrap-select.js:3413)

@caseyjhol
Copy link
Member

caseyjhol commented Jan 6, 2021

Yes, I'm working on this. twbs/bootstrap#30267 is causing me some issues currently, as I can't add a click listener to the button.

@samihoda
Copy link

samihoda commented Jan 9, 2021

Eagerly awaiting BS5 support!

@vlatro
Copy link

vlatro commented Jan 18, 2021

I would also really like bootstrap 5 support. Had to disable the bootstrap-select for now :(

@Gritmatch
Copy link

Same here!

@cal-zone
Copy link

Commenting to subscribe to notifications ("watch") this issue.

Apologies if there is some other way to do so, but I couldn't figure it out.

@CaFlow
Copy link

CaFlow commented Feb 7, 2021

Eagerly waiting for bootstrap 5 support. Had to also disable the bootstrap-select :(

@luciminea
Copy link

Hi guys !

Untill the new version is out, you can use the CSS for the Bootstrap 5 version and the JS for the 4.6. That will ensure the bootstrap-select is working.

I've just tested that ! Hope it helps you.

@chrisvanmeer
Copy link

Hi guys !

Untill the new version is out, you can use the CSS for the Bootstrap 5 version and the JS for the 4.6. That will ensure the bootstrap-select is working.

I've just tested that ! Hope it helps you.

For me that breaks my navbar dropdowns.

@luciminea
Copy link

Hi guys !
Untill the new version is out, you can use the CSS for the Bootstrap 5 version and the JS for the 4.6. That will ensure the bootstrap-select is working.
I've just tested that ! Hope it helps you.

For me that breaks my navbar dropdowns.

Yeap, some things will happen as the JS will no longer match the CSS. I'm not using too much of the Bootstrap JS, or dynamic elements, only the grid and general CSS. I preffer to build my own responsive navigation and modals.

@caseyjhol
Copy link
Member

This is close, but I'm unable to add click events on the button until twbs/bootstrap#30267 is resolved.

@DJScias
Copy link

DJScias commented Mar 24, 2021

Seems a PR (twbs/bootstrap#33442) fixing it has been merged, so that's good news at least.

@caseyjhol
Copy link
Member

caseyjhol commented Mar 26, 2021

Released in v1.14.0-beta2! jQuery is still required. You must use Bootstrap v5.0.0-beta3 or later.

@Joshdw
Copy link

Joshdw commented Mar 26, 2021

Released in v1.14.0-beta2! jQuery is still required.

Hey Casey, just some small fix to support BS5's modal:

1162: change to

'<button type="button" class="btn-close" aria-hidden="true"></button>' +

Simply change class from close to btn-close and remove &times;

Cheers thanks for fixing it for BS5!

@chrisvanmeer
Copy link

Sorry, but don't work with bootstrap 5 :(

Doesn’t seem to work for me either.

@RodrigoCanoM
Copy link

Error max-option
Bootstrap 5 v5.0.1
Bootstrap - select v1.14.0-beta2
jquery-3.5.1
Error Max-Options 2, selected 3
image

@sjamestasc
Copy link

There seems to be an issue with optgroups in v1.14.0-beta2

addOptgroup takes an index and the selectOtions

It is called from the loop for ( var len = selectOptions.length, i = startIndex; i < len; i++ ) {...

Rather than passing the loop variable as an index like this...
addOptgroup.call( this, i, selectOptions );

...it is called like this...
addOptgroup.call( this, startIndex, selectOptions );

...so if there are N optgroups in the raw select, the selectpicker will end up with N copies of optgroup[0], although it seems to get the optgroup label correct because I think item is scoped in the for loop and used in addOptgroup.

The above change was enough to fix it for us, although I am not sure if there are any knock-on effects from the change. It seems like it would be better to pass "item" to the addOptgroup function, or use
var config = {display: htmlEscape( dataGetter( optgroup, 'label' ) ),
instead of
var config = {display: htmlEscape( dataGetter( item, 'label' ) ),

I suspect this is a coding style choice I am not equipped to comment on though.

Other than this, it works great with BS5 from what we have seen.

@luciminea
Copy link

There seems to be an issue with optgroups in v1.14.0-beta2

addOptgroup takes an index and the selectOtions

It is called from the loop for ( var len = selectOptions.length, i = startIndex; i < len; i++ ) {...

Rather than passing the loop variable as an index like this...
addOptgroup.call( this, i, selectOptions );

...it is called like this...
addOptgroup.call( this, startIndex, selectOptions );

...so if there are N optgroups in the raw select, the selectpicker will end up with N copies of optgroup[0], although it seems to get the optgroup label correct because I think item is scoped in the for loop and used in addOptgroup.

The above change was enough to fix it for us, although I am not sure if there are any knock-on effects from the change. It seems like it would be better to pass "item" to the addOptgroup function, or use
var config = {display: htmlEscape( dataGetter( optgroup, 'label' ) ),
instead of
var config = {display: htmlEscape( dataGetter( item, 'label' ) ),

I suspect this is a coding style choice I am not equipped to comment on though.

Other than this, it works great with BS5 from what we have seen.

Can you provide a file with those modifications ? Or a few instruction on how to modify the source .js ?

@sjamestasc
Copy link

bootstrap-select.txt

See lines 1771 and 1772

@chrisvanmeer
Copy link

I would be interested in that too, just yeaterday I found the same “bug” with optgroups

@luciminea
Copy link

luciminea commented Jun 22, 2021

bootstrap-select.txt

See lines 1771 and 1772

I've opened it with Dreamweaver and for me it was line1718, but I've figured it out. I'm a programmer, but I don't do much work on JS, so I couldn't figure it out no matter how bad I've tried. I'm currently working ,like on the clock, on a project and I couldn't get pass this. I owe you a great deal, thanks again.

Here's the minified JS, for whomever needs it.
bootstrap-select.min.1.txt

Just change the extension to .js and you're good to go. Like sjamestasc said, don't know all the implications of this change, but I guess we'll figure it out.

@chrisvanmeer
Copy link

bootstrap-select.txt

See lines 1771 and 1772

That did the trick, thanks a lot!

@liamkeily
Copy link

As demonstrated here https://jsfiddle.net/p1gosxe8/2/ i was having some issues getting bootstrap-select working with Bootstrap 5.

To get it working correctly i had to:

  1. Include specific dev branch in package.json (because the latest fixes are not tagged up, see git diff v1.14-dev v1.14.0-beta2):
"bootstrap-select": "snapappointments/bootstrap-select#v1.14-dev",

2 Include bootstrap and bootstrap-select like this:

const bootstrap = window.bootstrap = require('bootstrap'); // without this bootstrap-select crashes with `undefined bootstrap`
require('bootstrap-select/js/bootstrap-select'); // we have to manually require the working js file

By default the package.json tells node to use dist/js/bootstrap-select.js, but this file is broken (perhaps out of date?). Manually requiring the js/bootstrap-select.js gets around this.

@luis-fss
Copy link

luis-fss commented Oct 24, 2021

Released in v1.14.0-beta2! jQuery is still required. You must use Bootstrap v5.0.0-beta3 or later.

bootstrap-select v1.14.0-beta2 does not show drop-down options using keyboard navigation (no mouse click) with Bootstrap v5.1.3: https://plnkr.co/edit/53lQjla5NiVGPuL0?preview
Works on Bootstrap v5.0.2

Oh, sorry! There is already an issue about this: #2665

@Kondzolko
Copy link

Hello everyone and want to say thank you for your js library, I'm not sure if I'm on the right place but I would like to report one 1 bug with groups selectpicker.

Options for groups generated from the first group.

So if we will have options like this

<optgroup label="Fruit">
  <option>Apple</option>
  <option>Orange</option>
</optgroup>

<optgroup label="Vegetable">
  <option>Corn</option>
  <option>Carrot</option>
</optgroup>
   

We will don't see options 'Corn' and 'Carrot'.

https://plnkr.co/edit/vZ9xghMuDhHFJKMc?preview

I Will be appreciative if somebody can take a look at that, I also will try to see if I can fix this problem and will share with you a solution if I will find it.

Thanks

@Kondzolko
Copy link

Kondzolko commented Oct 26, 2021

Hello everyone and want to say thank you for your js library, I'm not sure if I'm on the right place but I would like to report one 1 bug with groups selectpicker.

Options for groups generated from the first group.

So if we will have options like this

<optgroup label="Fruit">
  <option>Apple</option>
  <option>Orange</option>
</optgroup>

<optgroup label="Vegetable">
  <option>Corn</option>
  <option>Carrot</option>
</optgroup>
   

We will don't see options 'Corn' and 'Carrot'.

https://plnkr.co/edit/vZ9xghMuDhHFJKMc?preview

I Will be appreciative if somebody can take a look at that, I also will try to see if I can fix this problem and will share with you a solution if I will find it.

Thanks

I found where is the problem.
For Some reason we all the time sent index 0 'StartIndex'

the problem in line 1770 in this code
addOptgroup.call(this, startIndex, selectOptions);

please replace to
addOptgroup.call(this, i, selectOptions);

An example of code you can find here:
https://plnkr.co/edit/amuqKRkRe829UEVC?preview

@farhadmammadli
Copy link

farhadmammadli commented Nov 2, 2021

For anyone looking for cdn hosted file with fix applied (tested with bootstrap 5.0.1):
https://cdn.jsdelivr.net/gh/farhadmammadli/bootstrap-select@main/js/bootstrap-select.min.js
(thanks to @sjamestasc)

@kibblewhite
Copy link

For anyone looking for cdn hosted file with fix applied (tested with bootstrap 5.0.1): https://cdn.jsdelivr.net/gh/farhadmammadli/bootstrap-select@main/js/bootstrap-select.min.js (thanks to @sjamestasc)

That is working for me, thanks.

@fabienwnklr
Copy link

Hi , any progress on version 1.14 stable ? Thanks 😄

@NicolasCARPi
Copy link
Collaborator

@fabienwnklr I'm working on it yes.

@cspeer
Copy link

cspeer commented Feb 10, 2022

Hi @NicolasCARPi any chance we can speed things up a little? I know this probably isn't your main concern right now, but apparently a lot of people depend on it. I'm willing to throw in a 100 Euro donation and maybe someone else would like to chip in as well?

@NicolasCARPi
Copy link
Collaborator

Hello @cspeer, you're correct, it's not my main concern, but it's still on my radar. The thing is that I started hacking the code and removing old IE hacks so code gets more fluid and easier to grasp/fix bugs, but @caseyjhol wanted to keep IE support for the time being (and he is right, as it's a breaking change). I really want to push for more frequent updates, to keep the ball rolling, but I'm not in charge here, see #2228 (comment).

Maybe @caseyjhol can reconsider releasing a beta even without the fix he's working on? (after all, it is a BETA).

If money is burning your hand, know that donations are appreciated ;)

But I can't ensure anything, as I don't have all the cards in hand.

@therealsujitk
Copy link

@cspeer just thought I'd let you know, I use both bootstrap 5 and 4 together, 5 for most of my site, 4 only for bootstrap-select and it seems to work perfectly. I tried the beta version with bootstrap 5 but it had bugs that would've affected users if I had pushed it to production, so I decided to use the stable version with bootstrap 4 instead. Node.js allows you to use multiple versions of the same package.

@cspeer
Copy link

cspeer commented Feb 10, 2022

@NicolasCARPi Thanks for the speedy reply. I'd definitely be in favour of releasing a new beta ;) but for the time being, is there a dev branch that I could try? I didn't find one.

@therealsujitk Interesting idea. But if I'm understanding correctly, you'd use bs4 instead of bs5 on pages that require bs-select, right? I don't think that would work for me though, as the rest of the site very much depends on bs5. Switching to bs4 just on that one page, would break functionality, I'm afraid. Thanks though!

@therealsujitk
Copy link

But if I'm understanding correctly, you'd use bs4 instead of bs5 on pages that require bs-select, right?

Basically bootstrap 5 CSS + bootstrap 5 JS + bootstrap 4 JS (In that order). In our case, we have a single page. This might have conflicts, not sure, but in our case it didn't.

Bootstrap 5 is imported here and Bootstrap 4 JS is imported here.

@fabienwnklr
Copy link

sorry to insist.. but any progress ? :) i can contribute if necessary.. good luck :)

@hmtpandya
Copy link

@caseyjhol Is there any progress or update on Bootstrap 5 support? Can you please help with this?

@luanmarangon
Copy link

Para quem procura arquivo cdn hospedado com correção aplicada (testado com bootstrap 5.0.1): https://cdn.jsdelivr.net/gh/farhadmammadli/bootstrap-select@main/js/bootstrap-select.min.js (obrigado para@sjamestasc)

Thank you, working perfectly for me

@wings77
Copy link

wings77 commented May 5, 2023

este es un selec2 sin ajax se ve bien en boostrap5
image

este es un select5 con ajax, con bootstrap5 pierde el stilo y se reusa a ser responsive de resto funciona bien el buscado y lo demas

image

se desborda del navegador

image

@steven7mwesigwa
Copy link

@caseyjhol It isn't working for me using Bootstrap v5.2.2 and jQuery v3.6.1

The dropdown list doesn't show.

DEMO LINK: https://jsfiddle.net/theAccountant/baf17pys/3/

<!-- <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/5.2.2/css/bootstrap.min.css">
<!-- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.1/css/bootstrap-select.css" /> -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/2.0.0-beta1/css/bootstrap-select.min.css" />
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.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/5.2.2/js/bootstrap.min.js"></script>
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.1/js/bootstrap-select.min.js"></script> -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/2.0.0-beta1/js/bootstrap-select.min.js"></script>

@chadwtkns
Copy link

@steven7mwesigwa did you ever get this working?

@Madlhawa
Copy link

Madlhawa commented May 1, 2024

Just checking in to see if there's any update on bootstrap5 support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests