i have code on the onSelect event of the jquery ui datepicker and i now want to only run my function if the date has changed values (so if a user selects a date that was already there in the textbox, i don't want to run this code as it will be a redundant calculation). Here is my existing code.
$('#Milestone').datepicker({
dateFormat: 'dd M yy',
onSelect: calcUpdate
});
According to http://api.jqueryui.com/datepicker/#option-onSelect, you should try this:
$('#Milestone').datepicker({
dateFormat: 'dd M yy',
onSelect: function(curDate, instance){
if( curDate != instance.lastVal ){
//so, the date is changed;
//Do your works here...
}
}
});
The onSelect function receives 2 parameters which are used here; You can debug/console the values of the 2nd parameter to know more about it.
You can use data to store previously stored value and compare the current value to it.
Try this(put these statements in your document ready event):
$('#Milestone').data("prev", $(this).val());
$('#Milestone').datepicker({
dateFormat: 'dd M yy',
onSelect: function(dateText){
var prevDate = $(this).data("prev")
var curDate = dateText;
if(prevDate == curDate){
$(this).data("prev", curDate)
calcUpdate();
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With