question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bootstrap show.bs.modal / Datepicker show.bs.modal conflict

See original GitHub issue

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? 😉

Issue Analytics

  • State:open
  • Created 9 years ago
  • Reactions:12
  • Comments:27

github_iconTop GitHub Comments

34reactions
bioteckcommented, Jun 24, 2016

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') {
        //
    }
});
14reactions
mrlinnthcommented, Jul 24, 2015

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 });

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does bootstrap-datepicker trigger 'show.bs.modal' when it ...
When I select the input field that contains the date picker, the bootstrap modal event .on('show.bs.modal') gets triggered, which is super ...
Read more >
JavaScript · Bootstrap v5.0
Bootstrap provides custom events for most plugins' unique actions. Generally, these come in an infinitive and past participle form - where the infinitive...
Read more >
Why is Datepicker not highlighting dates on Bootstrap modal?
The date picker is not highlighting the selected dates on Bootstrap 3 model: modal-datepicker. This is my code: $('#myModal').on('shown.bs.modal', ...
Read more >
10 Most Common Bootstrap Mistakes That Developers Make
Bootstrap modal appears under background ... If the modal container or its parent element has a fixed or relative position, the modal will...
Read more >
UI page : jquery datepicker not working inside bootstrap modal
I had a datepicker (Jquery UI) inside the Bootstrap modal in a UI page which was working fine till now but since after...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found