TypeError Cannot read properties of undefined (reading 'backdrop') - bootstrap v5.2.1 modal #37304
Replies: 6 comments 4 replies
-
I bump into similar problem. Rather than initialize the modal upon mounting, I initialize it on demand. let modal = null;
function getModal() {
if (!modal) {
modal = new $bootstrap.Modal('#test-modal');
}
return modal
}
function toggleModal() {
// modal.toggle();
getModal().show()
} |
Beta Was this translation helpful? Give feedback.
-
modal1 = bootstrap.Modal.getOrCreateInstance('#modal1'); https://getbootstrap.com/docs/5.2/components/modal/#passing-options
|
Beta Was this translation helpful? Give feedback.
-
It shows my modal and the error. Someone said this error is from being passed an empty element, that isn't the case. GeoSot's solution also does not work. I tried setting the backdrop too. modal.js:158 Uncaught TypeError: Cannot read properties of undefined (reading 'backdrop') |
Beta Was this translation helpful? Give feedback.
-
Is there any solution for it? I am facing a similar issue and trying it since two days! |
Beta Was this translation helpful? Give feedback.
-
I had the same issues but when I used this, it worked fine. export const openModal = (name) => {
let modal = null;
if (!modal) {
var modalElement = document.getElementById(name);
modal = new bootstrap.Modal(modalElement);
}
modal.show();
}; |
Beta Was this translation helpful? Give feedback.
-
i just remove this: data-bs-toggle="modal" from the button & works fine |
Beta Was this translation helpful? Give feedback.
-
While using bootstrap modal I am facing this error ( TypeError Cannot read properties of undefined (reading 'backdrop') ) , which is tracked by our bug tracker, but I am unable to recreate this error. I tried recreating error with various browsers, browser versions, OS. This issue is not showing up on all browsers.
Bootstrap version used - v5.2.1
I initialized modal using JavaScript
Html code for these modals
The exact error is:
Note: lineNo1 is where modal2 is initializing
I also tried with modal options but error is still persisting
Beta Was this translation helpful? Give feedback.
All reactions