jonthornton / Datepair.js

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

Setting the date value programmatically after initialisation #120

Closed rlegge closed 3 years ago

rlegge commented 4 years ago

Hi, Im using this Datepair, but i'm struggling to set the date and time value programmatically after its been initialised. I can set each of the containers with a string value, but it doesn't save correctly. Im assuming I should be setting it to a JavaScript date object, but cant work out the syntax to do so correctly

Do you have an example of setting the date and time on a the datepair on a separate event?

Many Thanks.. Richard

jonthornton commented 4 years ago

Hi Richard, you'll want to use the refresh method, like this:

$('#someInput').val(someValue) // this can be a string
 datepair.refresh();

As long as the way you're setting the date/time is supported by the date/time pickers you're using, Datepair's refresh method will make sure pairing logic works correctly.