When will this happen
The event shown by .bs.modal does not fire when the modal also has a class of "fade". While show .bs.modal always works. See https://github.com/twbs/bootstrap/issues/11793
HTML:
<div class="modal fade" id="first" tabindex="-1" role="dialog" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content">Hello world from first modal</div> </div> </div> <div class="modal" id="second" tabindex="-1" role="dialog" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content">Hello world from second modal</div> </div> </div>
JQuery
$('.modal').on('shown.bs.modal', function() { //fired only in second modal console.info('shown.bs.modal'); }); $('.modal').on('show.bs.modal', function() { //fired always console.info('show.bs.modal'); });
Decision
For bootstrap v3.3.6, replace line 1010 with:
that.$element // wait for modal to slide in
What is the problem
Look at lines 1006-1015:
var e = $.Event('shown.bs.modal', { relatedTarget: _relatedTarget }) transition ? that.$dialog // wait for modal to slide in .one('bsTransitionEnd', function () { that.$element.trigger('focus').trigger(e) }) .emulateTransitionEnd(Modal.TRANSITION_DURATION) : that.$element.trigger('focus').trigger(e)
Without a transition (class fade ), the e event is fired immediately (on this element $.). With the transition, I'm not sure why, but somehow the bsTransationEnd event from the emulateTransitionEnd function is not handled by this. $ Dialog.one () i>. But with that. $ Element everything works.
rzehan
source share