Get 2024 Templates Mega Bundle!14 Bootstrap, Vue & React Templates + 3 Vector Sets
Get for 99$

How to create a modal in a modal?


If I click on a button, I want to show the button as we can see in the documentation at: https://preview.keenthemes.com/metronic8/vue/docs/#/modal.

Now I want to open a new modal, in the current modal. I want to close the current modal (temporary) and open the new modal. When I click on the button in the new modal, I want to close the new modal, and reopen the temporary closed modal.

How to manage this?


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (5)


Hi,

You can handle this using javascript.


  1. Get the modal instance.


  2. var myModalEl = document.getElementById("myModal")
    var modal = bootstrap.Modal.getInstance(myModalEl)


  3. Use show() and hide() functions to close and open your modals


  4. modal.show()
    modal.hide()



Please check bootstrap 5 official doc for more info:
https://getbootstrap.com/docs/5.0/components/modal/

I understand this. But what about if a modal gets NULL response with bootstrap.Modal.getInstance(myModalEl)? When is a modal associated with it? Is this only when you tab a button?



You can try to use getOrCreateInstance function in this case.


var myModalEl = document.querySelector("#myModal")
var modal = bootstrap.Modal.getOrCreateInstance(myModalEl)



I do understand that. But the question is. When is a modal being associated? When does is need to be created? And when not?



Hi,

If you are using attributes then you don't need to create an instance since it will already be initialized as an instance of the bootstrap modal.


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(