Super Sale Limited Time 50% OFF for All-Access Plans
Save 50% Now

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


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (1)


Hi,

If you are using Metronic 8.1.x you can use the global Metronic core components initialiser

KTComponents.init()
as described here.

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.


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(