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
Using
shownandhiddenevents instead ofshowandhideis not always possible. A better workaround is to check the event namespace: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…
@mrlinnth thank you, this solved the issue for me!
shown.bs.modalinstead ofshow.bs.modalI had the same problem but on the hide event, take the same path as the @conmer described:
Instead of using
hide.bs.modalI now usehidden.bs.modal. Works. Thanks @conmerI 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.