Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bootstrap modal and datepicker show events

When click on datepicker (http://www.eyecon.ro/bootstrap-datepicker/), his SHOW event fires, but the modal's SHOW.BS.MODAL fires too. Whhere is a problem?

$(document).ready(function() {
$('#ArrDate')
.datepicker()
.on("show", function(event){
    alert("Q");
});

$("#dlg3000to3100")
.on('show.bs.modal', function (event) {
    alert("W");
});

$("#dlg3000to3100")
.modal("show");
});

exampleExample

Thanks

like image 811
Misha Kondratev Avatar asked Oct 16 '13 08:10

Misha Kondratev


2 Answers

It seems to be a bug (or feature?) of the datepicker. What you can do is to prevent the show.bs.modal event reaching the dialog.

$('#ArrDate').on('show.bs.modal', function (event) {
    event.stopPropagation();
});

This will detect the event at the datepicker level and stop the event propagation, so show.bs.modal will not 'bubble up' to the dialog.

like image 89
Adam Szabo Avatar answered Oct 23 '22 22:10

Adam Szabo


Another work around is to swap the show.bs.modal with shown.bs.modal on modal event.

modal.on('shown.bs.modal', function (event) {
               // Do something
            });

however if it is not possible to swap show with shown or hide with hidden use the namespace check

modal.on('show.bs.modal', function(e) {
    if (e.namespace === 'bs.modal') {
         // Do something
    }

});

like image 4
Usman Shaukat Avatar answered Oct 23 '22 22:10

Usman Shaukat