I have a question on how to make sure whenever this hidden value changed, the datepicker will reload. Because the datepicker will used the hidden value to highlight the days. So whenever the hidden value changed, the highlighted days in datepicker also will change.
Here my code so far. $("#dates").val()
is a hidden value. sample of the value is 2013/11/11-2013/11/17
. This value will highlight the whole week (mon-sun). There's a previous and next button, which will changed the $("#dates").val()
by week eg:
2013/11/18-2013/11/24, 2013/11/25-2013/12/1
I have no problem to trigger if the hidden value is changed, the problem is I want the datepicker to reload once the hidden value changed. so that the highlighted week while changed accordingly. currently whenever the hidden value change, the highlighted week will remain the same.
I did try to used $( "#datepicker" ).datepicker( "refresh" );
whenever the hidden value changed, but still no luck. Please help me. Thanks
$(document).ready(function() {
var dates = $("#dates").val();
var lt = dates.split("-");
var ts = lt[0].split("/");
var te = lt[1].split("/");
var date1 = new Date(ts[0], ts[1]-1, ts[2]);
var date2 = new Date(te[0], te[1]-1, te[2]);
$(function(){
$('#datepicker').datepicker({
dateFormat: 'yy/mm/dd',
beforeShowDay: highlightDays,
onSelect: function(dateText, inst) {
$("#showdaybtn").addClass("fcurrent");
$("#showweekbtn").removeClass("fcurrent");
$("#showmonthbtn").removeClass("fcurrent");
$('#type').val('1');
var p = $("#gridcontainer").swtichView("day").BcalGetOp();
if (p && p.datestrshow) {
$("#txtdatetimeshow").text(dateText);
$("#hdnTempData").val(dateText);
}
showhideToday('day');
glbView = "day";
}
});
function highlightDays(date) {
if (date >= date1 && date <= date2) {
return [true, 'highlight', 'tooltipText'];
}
return [true, ''];
}
});
});
//to check if the hidden value changed
$(document).on('change', '#dates', function () {
$( "#datepicker" ).datepicker( "refresh" );
});