Skip to content

Instantly share code, notes, and snippets.

@DavidCramer
Created March 31, 2016 13:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidCramer/ba1722c373bf3772b75237ec43874149 to your computer and use it in GitHub Desktop.
Save DavidCramer/ba1722c373bf3772b75237ec43874149 to your computer and use it in GitHub Desktop.
Syncing two date picker fields in Caldera Forms
jQuery( function( $ ){
var first_date_id = 'fld_5161421', // date field ID to sync from
second_date_id = 'fld_8954452', // date field ID to sync to
date_forward = 1; // number of days to sync forward by
// get the first field
var first_date = $( '[data-field="' + first_date_id + '"]' );
if( !first_date.length ){
return;
}
// bind date change event
first_date.on("changeDate", function() {
var start_date = first_date.cfdatepicker('getFormattedDate');
var d = new Date( start_date );
var second_date = first_date.closest('.row').find('[data-field="' + second_date_id + '"]');
d.setDate( d.getDate() + date_forward );
second_date.cfdatepicker( 'setStartDate', new Date(d) );
if( !second_date.val().length ){
second_date.cfdatepicker( 'update', new Date(d) );
}
second_date.on("changeDate", function() {
second_date.cfdatepicker( 'hide' );
});
first_date.cfdatepicker( 'hide' );
});
})
@krashbit
Copy link

Hi Desertsnowman, please can you tell me how I can use this code to sync two date picker fields in caldera forms? Which is the path where I have to save the file in? Thank you in advice

@Giouris
Copy link

Giouris commented Mar 16, 2017

Dear Desertsnowman, I installed this code on a website of a client and was totally satisfied. It is a booking form, with a minimum stay of 3 days. I set the date_forward to 3. Now my client found, that it is possible to input check in date, after that check out date, and go back to the check in date and change it. Thus avoiding the minimum stay of three days. I think the binding should go in two directions. Can you change this code accordingly?
Regards, Giouris

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment