Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to destroy bootstrap modal window completely?

I've made use of modal window for a wizard implementation which has around 4,5 steps. I need to destroy it completely after the last step(onFinish) and OnCancel step without having a page refresh. I can of course hide it, but hiding modal windows restores everything as such when i open up it again. Could anyone help me on this issue?

Thanks Any hints answers are helpful for me.

like image 369
Akki Avatar asked Nov 01 '12 12:11

Akki


People also ask

How do I dispose of bootstrap modals?

Live Demo: Dispose Bootstrap Modal Using jQuery. First launch modal, then close it, then press "Dispose Modal" button to remove the modal data stored on the DOM element. Press Ctrl+Shift+J (Windows / Linux) or Cmd+Opt+J (Mac) to open the browser console panel.

What is data dismiss modal?

modal-header class is used to define the style for the header of the modal. The <button> inside the header has a data-dismiss="modal" attribute which closes the modal if you click on it. The . close class styles the close button, and the . modal-title class styles the header with a proper line-height.


2 Answers

if is bootstrap 3 you can use:

$("#mimodal").on('hidden.bs.modal', function () {     $(this).data('bs.modal', null); }); 
like image 65
user2612497 Avatar answered Sep 18 '22 07:09

user2612497


NOTE: This solution works only for Bootstrap before version 3. For a Bootstrap 3 answer, refer to this one by user2612497.

What you want to do is:

$('#modalElement').on('hidden', function(){     $(this).data('modal', null); }); 

that will cause the modal to initialize itself every time it is shown. So if you are using remote content to load into the div or whatever, it will re-do it everytime it is opened. You are merely destroying the modal instance after each time it is hidden.

Or whenever you want to trigger the destroying of the element (in case it is not actually every time you hide it) you just have to call the middle line:

$('#modalElement').data('modal', null); 

Twitter bootstrap looks for its instance to be located in the data attribute, if an instance exists it just toggles it, if an instance doesn't exist it will create a new one.

Hope that helps.

like image 27
Conar Welsh Avatar answered Sep 20 '22 07:09

Conar Welsh