Tempus-dominus: Input change event is never fired. How to do a callback function on date select?

Created on 2 Feb 2015  路  5Comments  路  Source: Eonasdan/tempus-dominus

I am trying to call a function once the input value is changed when a date is selected, but the change callback is never fired when using the datetimepicker. Below is the code. Is there any way to call a callback function once the date is changed?

<div class="form-group">
  <div id="timepicker" class="input-group date">
    <input type="text" class="form-control"><span class="input-group-addon"><i class="glyphicon glyphicon-time"></i></span>
  </div>
</div>
<script>
  $('#timepicker').datetimepicker({
    format: "dddd, MMMM Do YYYY, h:mm a",
    defaultDate: moment(),
    sideBySide: true,
    showTodayButton: true,
    keepOpen: true,
  });

  $('#timepicker, #timepicker input').change(function(e){
    e.preventDefault();
    lookup(); //never happens
  });
</script>

Most helpful comment

Check out the docs for more info, short answer is:
$('#timepicker').data('DateTimePicker').on('dp.change', function(e) { });
No need to preventDefault in that function

All 5 comments

Check out the docs for more info, short answer is:
$('#timepicker').data('DateTimePicker').on('dp.change', function(e) { });
No need to preventDefault in that function

This is what worked for me:

$("#timepicker").on("dp.change",function (e) {
            lookup();
});

Hey guys,

Query :
I need you help I Want to disable past Hours and minutes from current time.
so how to do it right now i am using .

 $('#timepicker1').datetimepicker({
     pickDate: false,
     pickSeconds: false,
   });

How to do this could you please help me ?

I am waiting for your reply.

Thanks,
Pratik Mehta

dp.change is not working in inline ? Is there a work around for inline update ? Neither normal jquery event 'change' works.

Never mind, I was trying with
$(document).on('dp.change', '#element', function(e){
// something here
});

But the following worked for me:
$("#element").on("dp.change",function (e) {
// something here
});

Thanks.

Was this page helpful?
0 / 5 - 0 ratings