Skip to content
This repository has been archived by the owner on Apr 8, 2022. It is now read-only.

With Bootstrap usage doesn't work with Bootstrap 5 #327

Closed
cpsievert opened this issue Apr 7, 2021 · 7 comments · Fixed by #329
Closed

With Bootstrap usage doesn't work with Bootstrap 5 #327

cpsievert opened this issue Apr 7, 2021 · 7 comments · Fixed by #329

Comments

@cpsievert
Copy link
Contributor

cpsievert commented Apr 7, 2021

Here's a minimal example, adapted from https://github.com/itsjavi/bootstrap-colorpicker#with-bootstrap, which yields the following error:

https://codepen.io/cpsievert/pen/yLgzxqL

Uncaught TypeError: Cannot read property 'tip' of undefined
    at PopupHandler.createPopover (PopupHandler.js:237)
    at PopupHandler.bind (PopupHandler.js:117)
    at Colorpicker.init (Colorpicker.js:200)
    at new Colorpicker (Colorpicker.js:161)
    at HTMLInputElement.<anonymous> (plugin.js:31)
    at Function.each (jquery-3.4.1.js:367)
    at jQuery.fn.init.each (jquery-3.4.1.js:202)
    at jQuery.fn.init._jquery2.default.fn.<computed> [as colorpicker] (plugin.js:24)
    at HTMLDocument.<anonymous> (yLgzxqL:55)
    at mightThrow (jquery-3.4.1.js:3557)

(If you replace //unpkg.com/bootstrap@5.0.0-beta3/dist/js/bootstrap.bundle.js with //unpkg.com/bootstrap@4.3.1/dist/js/bootstrap.bundle.js in that codepen, things work fine)

@daidensacha
Copy link

daidensacha commented Apr 8, 2021 via email

@cjbarth
Copy link

cjbarth commented Apr 12, 2021

I experience an issue with Bootstrap 5 and this control as well. I get an error saying that this.popoverTarget.popover is not a function. When I move back to 4.x, things work fine. Given how different popovers work between Bootstrap 4 and 5, I'm not surprised this is an issue.

@itsjavi
Copy link
Owner

itsjavi commented Apr 23, 2021

Have you tried loading the popover package separately?

In the "with bootstrap" example, it includes the popover package because it's loading the bootstrap bundle: /unpkg.com/bootstrap@4.3.1/dist/js/bootstrap.bundle.min.js

Edit: Ok I see that in BS5 they still have his bundle. As Chris suggested, the popover API might have changed and it's not compatible anymore :(

@hkvstore
Copy link

For Bootstrap 5, change this line:

this.popoverTip = $(this.popoverTarget.popover('getTipElement').data('bs.popover').tip);
to

if (bootstrap) // Bootstrap 5  
	this.popoverTip = $(bootstrap.Popover.getInstance(this.popoverTarget[0]).getTipElement());
else // Boostrap 4
	this.popoverTip = $(this.popoverTarget.popover('getTipElement').data('bs.popover').tip);

@fritzfr
Copy link

fritzfr commented May 18, 2021

Above solution is not complete. For me, the error is above the mentioned line:

this.popoverTarget.popover is not a function
    at PopupHandler.createPopover (bootstrap-colorpicker.js:4188)

@hkvstore
Copy link

You need to include either bootstrap 4 or 5 .js first.

cpsievert added a commit to cpsievert/bootstrap-colorpicker that referenced this issue Jun 1, 2021
itsjavi pushed a commit that referenced this issue Jun 3, 2021
* Close #327: Fix Bootstrap 5 usage
@OlivierGrimard
Copy link

OlivierGrimard commented Dec 3, 2021

For Bootstrap 5.1.3, I was getting the error "Cannot read properties of null (reading 'getTipElement')" so I changed the method getInstance to use getOrCreateInstance.

this.popoverTip = $(bootstrap.Popover.getOrCreateInstance(this.popoverTarget[0]).getTipElement());

this.popoverTip = useGetInstance ? (0, _jquery2.default)(bootstrap.Popover.getInstance(this.popoverTarget[0]).getTipElement()) : (0, _jquery2.default)(this.popoverTarget.popover('getTipElement').data('bs.popover').tip);
To
this.popoverTip = useGetInstance ? (0, _jquery2.default)(bootstrap.Popover.getOrCreateInstance(this.popoverTarget[0]).getTipElement()) : (0, _jquery2.default)(this.popoverTarget.popover('getTipElement').data('bs.popover').tip);

I hope it can help someone.

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

Successfully merging a pull request may close this issue.

7 participants