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

Date not cycling properly #117

Closed Especially closed 5 years ago

Especially commented 5 years ago

This is similar to this error however, I have a code where we duplicate the values from a previous date-paired object, I then reinitialize the datepair script, however my error occurs when I change the start date. When I change the start date, the end date duplicates the same day, rather than +1, despite the time being the next day.

Here's my code that I use $(".dates").datepair('remove'); $("form[data-shift-count='"+(form_id+1)+"'] .new_indiv_shift_single_location").val(loc_val).trigger('change'); $("form[data-shift-count='"+(form_id+1)+"'] .new_indiv_shift_single_employee_req").val(emp_val).trigger('change'); $("form[data-shift-count='"+(form_id+1)+"'] .date.start").val(ds_val).trigger('change'); $("form[data-shift-count='"+(form_id+1)+"'] .date.end").val(de_val).trigger('change'); $("form[data-shift-count='"+(form_id+1)+"'] .time.start").val(ts_val).trigger('change'); $("form[data-shift-count='"+(form_id+1)+"'] .time.end").val(te_val).trigger('change'); $("form[data-shift-count='"+(form_id+1)+"'] .caller").val(cal_val).trigger('change'); $("form[data-shift-count='"+(form_id+1)+"'] .comments").val(com_val).trigger('change'); $(".dates").datepair();

What's happening here is im creating a new object through javascript, and inputting values from the previous form into the new created object. Everything works perfectly, EXCEPT when I change the new element's start date, and the re-initialized datepair does not recognize that the end-time is into the next day. I hope this makes sense, I for some reason cannot make a fiddle.

Especially commented 5 years ago

I think removing the script and then initializing it again is what causes this error.

jonthornton commented 5 years ago

I wish I could help - this is complicated enough that I need to see a working example in order to debug.

Especially commented 5 years ago

https://jsfiddle.net/Wimbledon/4z5gys2L/69/ Here's the fiddle

jonthornton commented 5 years ago

In the jsfiddle it looks like the inputs are all being placed into one div. Datepair.js needs the inputs to be grouped into separate containers.

Especially commented 5 years ago

https://jsfiddle.net/Wimbledon/4z5gys2L/75/ Here we see 'getTime' error in the console log when applying to separate containers