Bootstrap-datepicker does not select input change event

I have an input on which I want to change the date. When the input value changes, I want to make a callback.

If I call the datepicker function (from bootstrap-datepicker https://github.com/eternicode/bootstrap-datepicker ), I can no longer connect to the change event. (Oddly enough, other events seem to be working fine)

This is what I have tried so far:

(using trunk)

events: {
  'changeDate :input' : 'onUpdateField'
},

or using jquery directly

$('#Fundacion').on('change', this.onUpdateField);

If I just comment on the next line

$('#Fundacion').datepicker({
  autoclose : true,
[...]

Event triggered.

On the other hand, changeDate evet is called, but only when the date is changed using the mouse or arrows. I want to catch an event when the user simply dials a different date.

(https://github.com/eternicode/bootstrap-datepicker/blob/master/js/bootstrap-datepicker.js), , "" .

+5
3

, . 500 ( ).

var current = $('.transaction-date').val();
function keep_checking() {

    if (current != $('.transaction-date').val()) {
        alert('change happened');
        current = $('.transaction-date').val();
    }
    setTimeout(keep_checking, 500);
}
keep_checking();

UPDATE

, changeDate.

http://www.eyecon.ro/bootstrap-datepicker/

:

jQuery('#dp1').datepicker().on('changeDate', function(ev){
     alert('date is changed');
});
+7

In my case, it was enough to take two simple steps:

  • Add a change event listener for input (it will catch an event when the user types a different date)

    $('#dateInput').on(change, doSomethingOnChange);
    
  • Add a datepicker changeDate event (it will trigger a change event from the first step when the date is changed using the mouse or arrows)

    input.datepicker().on('changeDate', function(){
        $(this).trigger('change');
    });
    
0
source

All Articles