uxsolutions / bootstrap-datepicker

A datepicker for twitter bootstrap (@twbs)
Apache License 2.0
12.66k stars 6.08k forks source link

Datepicker inside bootstrap modal triggers show.bs.modal event on field focus #2370

Open alexandrubau opened 6 years ago

alexandrubau commented 6 years ago

Expected behaviour

Focusing on a Bootstrap Datepicker field should not trigger the "show.bs.modal" event.

Actual behaviour

Focusing on a Bootstrap Datepicker field triggers "show.bs.modal" event. It happens for "hide.bs.modal" also.

Datepicker version used

Datepicker - 1.8.0 Bootstrap 4.0

Example code

https://jsfiddle.net/aq9Laaew/6718/

papakay commented 6 years ago

Please is there an update on this. I'm also having similar issue.

Thanks.

alexandrubau commented 6 years ago

@papakay as a workaround you can use this:

$('#register-modal').on('hidden.bs.modal', function(event){

    if ($(event.target).is('#register-expires-at-field')) { // the id of the element with datepicker
        return;
    }

    //
});
kolosseo commented 4 years ago

Than you very much @alexandrubau for the trick, you saved my day!!! :+1: Anyway, I noticed the problem is actually with the modal opening (not closing), so I had to correct your solution with the event show.bs.modal. Here is my working code:

$('#register-modal').on('show.bs.modal', function(event) {
    if ($(event.target).is('#register-expires-at-field')) { // the id of the element with datepicker
        return;
    }
    // ...
});