Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap Datepicker on change firing 3 times

Tags:

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

like image 842
Hard Fitness Avatar asked Mar 24 '14 15:03

Hard Fitness


1 Answers

You should be using the "changeDate" event. For example:

var datePicker = $('.date-picker').datePicker().on('changeDate', function(ev) {     //Functionality to be called whenever the date is changed }); 

Please view the documentation here for more info on this event.

like image 75
seeARMS Avatar answered Oct 04 '22 09:10

seeARMS