jonthornton / Datepair.js

A javascript plugin for intelligently selecting date and time ranges, inspired by Google Calendar.
https://www.jonthornton.com/Datepair.js
358 stars 87 forks source link

Duration does not show up correctly when updating time through code #62

Closed isupersid closed 8 years ago

isupersid commented 8 years ago

Hi,

Here is the jsfiddle for this issue: http://jsfiddle.net/2gvnwnwy/3/

There are really 2 problems here but I am concerned with the duration not showing up right now.

  1. Run the fiddle -- this will update the datepair fields with today's date with time snapped to next half hour.
  2. Select the date field -- notice that the days aren't highlighted on the calendar.
  3. Click on the second time field to see that duration shows up now.
  4. Hit the advance button
  5. Look at the duration by selecting the second time field. -- it is computed from the previous value

Expected: The duration should update when programmatically advancing time.

jonthornton commented 8 years ago

notice that the days aren't highlighted on the calendar

That's the red flag. Datepair gets the date values from the datepicker. If the datepicker isn't showing the correct value, Datepair isn't going to work.

Use the datepicker/timepicker update methods instead of $.val():

function updateDateTime(fromDate, fromTime, untilTime, untilDate) {
    if (fromDate) {
        fromDateField.val(fromDate.format('MM/DD/YYYY'));
    }

    if (untilDate) {
        untilDateField.datepicker('update', untilDate.format('MM/DD/YYYY'));
    }

    if (fromTime) {
        fromTimeField.timepicker('setTime', fromTime.format('h:mma'));
    }

    if (untilTime) {
        untilTimeField.timepicker('setTime', untilTime.format('h:mma'));
    }

    datepair.refresh();
}```
isupersid commented 8 years ago

Opened related issue #63 about duration not showing up correctly.