jschr / bootstrap-modal

Extends the default Bootstrap Modal class. Responsive, stackable, ajax and more.
http://jschr.github.io/bootstrap-modal/
Apache License 2.0
5k stars 1.09k forks source link

Never fired hidden.bs.modal on the second close #228

Open nchankov opened 10 years ago

nchankov commented 10 years ago

When you open the modal or the first time then close it, and again open it it never fires hide.bs.modal as well as hidden.bs.modal

I've prepared a demo: http://jsfiddle.net/84yTH/3/

To reproduce:

  1. Click on the button
  2. Close the modal (Closed text appeared)
  3. Click on the button again
  4. Close the modal - nothing appeared

If the bootstrap-modal.js is removed it fires correctly the event every time: http://jsfiddle.net/84yTH/4/

Also I can't close the modal when I press Esc key (am I doing something wrong or it's a bug?)

nchankov commented 10 years ago

Forget about close with Esc, it's working on the demo, so I messed up something on my project or it collide with something else.

I've seen that you are firing hidden event which work all the times, so I will use it instead of hidden.bs.modal for now

amites commented 10 years ago

I'm seeing the same issue with 'shown.bs.modal' -- will put a jsfiddle together or perhaps a fork -- but wanted to get the report in

simple approach to spot, add

$('#ajax-modal').on('shown.bs.modal', function(e) {
    console.log('hello bind');
});

console will report the first time but lost after that -- with most recent git pull it also loses the animation graphic while loading the 2nd+ time

caseyjhol commented 10 years ago

+1

Mantus667 commented 10 years ago

+1

RickWong commented 10 years ago

+1 This project seems abandoned.

jschr commented 10 years ago

Sorry this went unnoticed. I believe the issue lies somewhere in jQuery (still hunting down the exact cause) but this plugin was desgined for BS2 originally and still fires the non-namespaced version of the events. jQuery seems to be able to match the namespace but only on the first call? Bizarre. If you change your event listeners to the BS2 versions you shouldn't run into this issue:

$modal.on('show', function () { ... }
$modal.on('shown', function () { ... }
$modal.on('hide', function () { ... }
$modal.on('hidden', function () { ... }
RickWong commented 10 years ago

Thanks. I can confirm that the above work-around fixes it for now.

GrantRWinter commented 10 years ago

+1

iruy commented 9 years ago

You have to use jquery like this for delegation: $(container).on(event, selector, function(){});

$(document).on('hidden.bs.modal', '#responsive', function(){ /your code/ });

liuruting commented 9 years ago

Thanks. Using show, shown, hide and hidden works.

albertofortes commented 8 years ago

@iruy +1

UmeshAawte commented 8 years ago

hidden.bs.modal did worked for but shown.bs.modal did not.

borland502 commented 8 years ago

Thank you @iruy +1.

Valamiro commented 8 years ago

Thank you @iruy +1.

adamcurl commented 7 years ago

Thank you @iruy +1.

AhmedEzzat12 commented 4 years ago

Thanks $(document).on('hidden.bs.modal', '#responsive', function(){ /your code/ }); worked for me