<script type="text/javascript">
// When the document is ready
$(document).ready(function () {
$('.datepicker').datepicker({
format: "yyyy-mm-dd",
}).on('changeDate', function(ev){
// do what you want here
$(this).datepicker('hide');
}).on('changeDate', function(ev){
if ($('#startdate').val() != '' && $('#enddate').val() != ''){
$('#period').text(diffInDays() + ' d.');
} else {
$('#period').text("-");
}
});
});
</script>
So here's what my datepicker looks like. So basically when I change date by clicking mouse it works good, however when I manually change date with keyboard or manually clear the date change date event doesn't get called. Is this a bug or am I doing something wrong here ?
In version 2.1.5
changeDate has been renamed to change.dp so changedate was not working for me
also needed to change css class from datepicker to datepicker-input
Date formate also works in capitals like this data-format='MM-DD-YYYY'
it might be helpful for someone it gave me really hard time :)
I found a short solution for it. No extra code is needed just trigger the changeDate event. E.g.
$('.datepicker').datepicker().trigger('changeDate');
The new version has changed.. for the latest version use the code below:
You have to use the
change
event on the input itself if you want to respond to manual input, because thechangeDate
event is only for when the date is changed using the datepicker.Try something like this:
Try this:
This should make it work in both cases