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

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
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 (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:


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
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  :(