Bootstrap-datepicker: datepicker `change` event fired twice.

Created on 13 Jan 2015  路  11Comments  路  Source: uxsolutions/bootstrap-datepicker

When 'change' event set to datepicker field.

'change' event fire twice.

In repo vizjerai/bootstrap-datepicker.

This issue is fixed like this.

Fix multiple calls to change #4
commit

How is going at this repo?

This fixing is correct?

Most helpful comment

Still see this issue in version 1.6.4.

All 11 comments

Yes I saw that patch before, I'm going to look at that issue soon and see if the patch is correct!

OK. Thanks.

:+1:

Fixed in #1337

Does this mean the issue was fixed in 1.5.0?

This is because I'm using 1.6.0 and I'm still getting the event triggered 3 times on the 'change dp.change' event. Please advise if I'm doing something wrong. Thank you

this problem persist now in range datepicker, when select date in a input it cause two events

Still see this on 1.6.1

Can you guys provide a jsfiddle to show if the problem still persists? It should be fixed with the pr, but maybe some new code broke it against

Just change it to...
.on('changeDate',function() { do_staff(); });

Still see this issue in version 1.6.4.

In my case, I am using daterangepicker with angular. My purpose is to watch any change in the model that stores the date range value and save it for an AJAX call later. I face the same issue as it hits the event twice whenever the date is changed, even if I select 'Today':聽_Once it is object with startDate and endDate properties, and the other time it is a string._

It聽can be made use of as an advantage.

$scope.$watch(
    'rangeOfDate',
    function (newValue) {
        // Due to a known bug of open source library daterangepicker, the event is hit twice 
        //upon change. Once it is an object, and once it is a string. So, use appropriately.
        var selectedDateRange = new Object();
        if (typeof (newValue) == 'object') {
            selectedDateRange.startDate = new Date(newValue.startDate).toLocaleDateString();
            selectedDateRange.endDate = new Date(newValue.endDate).toLocaleDateString();
            //Do as you wish with this custom object
        }
        else if (typeof (newValue) == 'string') {
            alert("string");
        }               
    },
    false);


Was this page helpful?
0 / 5 - 0 ratings