The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group
From To Dates - Jump to the month of the "from date"
Hi! I have a "start date field" (checkin) and "end date field" (checkout) and I've applied this script below through Code Snippets. The past dates can't be selected now (that's all good), so when I set the "start date" to January 1st 2019, for example, on the "end date field" datepicker, the dates before January 1st 2019 are all blacked out. This is all great.
What I want to achieve is that the second datepicker jumps to the month of the Start Date selected. I am guessing it would be something like minDate of checkout field should be = checkin value.. How do I achieve this?
add_action('frm_date_field_js', 'start_and_end_dates', 10, 2);
function start_and_end_dates($field_id, $options){
$key_one = 'checkin';// Change pickup to the KEY of the first date field
$key_two = 'checkout';// Change dropoff to the KEY of the second date field
$days_between = 1;// Change 0 to the number of days that should be between the start and end dates
if ( $field_id == 'field_'. $key_one ) {
echo ',beforeShowDay: function(dateOne){var secondDate=$("#field_' . $key_two . '").datepicker("getDate");if(secondDate==null){return[true];}var modDate=new Date(secondDate);modDate.setDate(modDate.getDate()-' . $days_between . '+1);return [(dateOne < modDate)];}';
} else if ( $field_id == 'field_' . $key_two ) {
echo ',beforeShowDay: function(dateTwo){var firstDate=$("#field_' . $key_one . '").datepicker("getDate");if(firstDate==null){return[true];}var modDate=new Date(firstDate);modDate.setDate(modDate.getDate() + ' . $days_between . '-1);return [(dateTwo > modDate)];}';
}
}
December 3, 2018 at 5:01 am
Hi again, the support replied that I should set the defaultDate of the second datepicker to the date selected in the first datepicker. If anyone could help me out how this can be done, it would be great.
Discussion closed.