Bootstrap-datepicker: clearDate trigger also triggers changeDate

Created on 2 May 2017  路  3Comments  路  Source: uxsolutions/bootstrap-datepicker

Expected behaviour

I was expecting the clearDate to be indpendent of the changeDate. But whenever the clearDate is fired, it also triggers the change date immedietyly after so there is no way of singling out events.

Tell us what should happen.
clearDate should only fire when the clear button is true and clicked.

Actual behaviour

Tell us what happens instead.
When the clearDate is fired, it also triggers the change date immedietyly after.

Datepicker version used

1.6.4 dist.

Example code

        $(".input-group.date").datepicker({
            clearBtn: true
        }).on("clearDate changeDate", function(event) {
                console.log("Event type: " + event.type);
                if(event.type == "clearDate") {
                    // console.log("Clear Date selected, stopping propogation");
                    // event.stopPropagation();
                    console.log("Clear Date selected, preventing default");
                    // event.preventDefault();
                }
                else console.log("this always gets triggered...");
        });

Most helpful comment

Is it still an issue? I am experience the same problem with 1.9.0.

All 3 comments

got the same problem today, I have some cleanup functionality which I'd like to fire on clearDate, instead I get 2 events fired clearDate and changeDate.

my workaround is to check for e.date inside changeDate event. If it's empty that means a clearDate was triggered.

Is it still an issue? I am experience the same problem with 1.9.0.

I end it up like this:

Example Code

var clearBtnClicked = false;

$('.input-group.date').datepicker()
   .on("changeDate clearDate", function (e) {
      if (e.type == 'clearDate') {
         this.clearBtnClicked= true;
         // put the logic
      } else {
         var date = e.date;

         if (this.clearBtnClicked ) {
            this.clearBtnClicked= false;
            // put the logic
         } else {
            // put the logic
         }
            // Executing logic
      }
});

Still hoping this issue will be closed after the next patch.

Was this page helpful?
0 / 5 - 0 ratings