bootstrap-datepicker: Bootstrap show.bs.modal / Datepicker show.bs.modal conflict

Hi,

I found some weird behaviour when using Datepicker inside a Bootstrap v3 Modal.

I have something like this

$("#my-modal").on("show.bs.modal", function() {
    // reset my values
});

$("#my-datepicker").datepicker();

Everytime I click on a datepicker input my “reset my values” code gets executed I found a solution here: http://stackoverflow.com/a/20059099/1909698

Which means my code works after adding:

$("#my-modal").on("show.bs.modal", function() {
    // reset my values
});

$("#my-datepicker").datepicker().on('show.bs.modal', function(event) {
    // prevent datepicker from firing bootstrap modal "show.bs.modal"
    event.stopPropagation();
});

Is it a bug or a feature? 😉

About this issue

  • Original URL
  • State: open
  • Created 10 years ago
  • Reactions: 12
  • Comments: 27

Commits related to this issue

Most upvoted comments

Using shown and hidden events instead of show and hide is not always possible. A better workaround is to check the event namespace:

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

Just faced with this issue in past a couple of hours. We solved it by using “shown.bs.modal” instead of “show.bs.modal” on modal event.

$(“#my-modal”).on(“shown.bs.modal”, function() { // reset my values });

6 years later and this is still a problem… image

@mrlinnth thank you, this solved the issue for me!

shown.bs.modal instead of show.bs.modal

I had the same problem but on the hide event, take the same path as the @conmer described:

Instead of using hide.bs.modal I now use hidden.bs.modal. Works. Thanks @conmer

            modal.on('hidden.bs.modal', function (event) {
                $(modal).remove();
            });

I had the same issue with an ‘hide.bs.modal’-event for the modal. It was triggered when datepicker inside the modal was closed. Adding .on(‘hide’,function(e){ e.stopPropagation() }) to my datepicker fixed this.