Refreshing datepicker

Refreshing datepicker

I am setting the date of the datepicker programmatically under certain conditions. For example, I have an "arrival" and a "departure" input (type=hidden), each with their own datepicker. If the arrival is later in time than the departure, my code is automatically updating the departure to 1 day after the arrival that was just set.

My issue is that my datepicker for departure does not highlight the selected date. It works fine if I *use* the departure datepicker to manually set the date, but when I try to set the datepicker via javascript, the selected date is incorrect. Seems like the datepicker('refresh') function is highlighting today as the currently selected date.

Here's my code (I'm using datejs functions btw):
/**
 * @param arrivalDateToSet The Date object to use to set the input.
 **/
function test(dateToSet) {
  ...
  var otherDate = Date.parse($checkOutInput.attr('value'));
 
  // if departure is undefined or is less than arrival
  if(!otherDate || arrivalDateToSet.compareTo(otherDate) >= 0) {
    // this mutates the date
    arrivalDateToSet.add(1).day();
    setDateUtil(arrivalDateToSet, CHECK_OUT);
    // also have to update other datepicker manually
    $checkOut.datepicker('setDate', arrivalDateToSet);
    $checkOut.datepicker('refresh');
  }
}

Here is some clarification on variables and methods above:
$checkOut - The div that the datepicker was created on (<div id="check-out-datepicker"></div>).
$checkOutInput - The hidden input that contains a string value for the check out, or departure date.
setDateUtil() - This function is setting the hidden input and affecting some other html elements.

Any help would be greatly appreciated.




























    • Topic Participants

    • strom