Bootstrap Datepicker on change firing 3 times

datepicker, javascript, jquery, twitter-bootstrap

Solution

it does not fix the problem, but i was using the datepicker to send through an ajax post, so the 3 change events was causing me problems - the 3rd event always failed. even if the documentation says to use a changeDate event, it doesn't seem right to me to fire the input tag's change event 3 times. the value isn't changing 3 times!

I wrote a simple 'debounce' function to get around the problem. doesn't fix the issue - which is due to multiple change events being fired from the methods: setValue (line 508) _setDate:(line 1048) and setValue (line 508) (version 1.3.0) of the widget.

 var lastJQueryTS = 0 ;// this is a global variable.
 ....
 // in the change event handler...
    var send = true;
if (typeof(event) == 'object'){
    if (event.timeStamp - lastJQueryTS < 300){
        send = false;
    }
    lastJQueryTS = event.timeStamp;
}
if (send){
    post_values(this);
}

it is pretty simple, just finds the jquery 'event', and makes sure that values in a window of 300ms are ignored. in my testing this all happened in 30 msec or so.

Problem

Hi I have been trying to just get the date of a bootstrap date picker and have been able to but it seems to fires 3 times. NOTE: This is not jquery date picker but bootstrap date picker. Using this date picker: https://github.com/eternicode/bootstrap-datepicker, not older eyecon.ro one. ``` $(".date-picker").on("change", function(e) { contents = $(this).val(); id = $(this).attr('id'); console.log("onchange contents: " + contents); console.log("onchange id: " + id); }); ``` HTML: ``` <input id="start_date" type="text" data-date-format="yyyy-mm-dd" class="date-picker form-control" /> ``` I have used a few other options other than change, like ``` $('.date-picker').datepicker().change(function(){}; ``` But this does not close date picker, hoping there is an easy solution to this. thx

Original source