How to have a dynamic modal in Metronic with all modules support?
Hello,
I am trying to have a dynamic through which I can call an external file in php like
<a data-bs-toggle="modal" data-bs-target="#LCPS_POPUP" data-load-url="addvideocategory.php?id=".$row["id"]."\"" data-title="".$mainCatTitle."" class="menu-link px-3">...
</a> I have a modal with LCPS_POPUP and I am opening it with:
$("#LCPS_POPUP").on("show.bs.modal", function (e) {
var loadurl = $(e.relatedTarget).data("load-url");
var title = $(e.relatedTarget).data("title");
$(this).find(".modal-body").load(loadurl);
$(this).find(".modal-title").html(title);
});
}); Popup is opening with dynamic title and content but popup is getting Metronic javascript components like image input viewer. I have tried declaring KTComponents.init(); and also KTImageInput.init(); inside the function but it does not work unless I I do:
$.getScript("./../assets/js/scripts.bundle.js", function(jd) {}); with in the function. But then javascript stops working on main page.
Please help me with this as I have been trying to solve it for 2 days now and no clue whatsoever.
Thanks
Replies (1)
Hi,
If you are using Metronic 8.1.x you can use the global Metronic core components initialiser
KTComponents.init() You just need to call the above init method on the modal shown event after the new HTML elements population in order to initialize the newly loaded components such as Menus, Select2, etc as defined in
src/js/components/_init.js.Regards.