Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
8
rated 0 times [  15] [ 7]  / answers: 1 / hits: 27828  / 10 Years ago, mon, march 24, 2014, 12:00:00

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


More From » jquery

 Answers
4

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.


[#71808] Sunday, March 23, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
nikoguym

Total Points: 339
Total Questions: 106
Total Answers: 95

Location: Mali
Member since Sat, Feb 12, 2022
2 Years ago
;