I have two ACF Date Time Picker fields for an event entry, startdate and enddate. To prevent a negative time span I’d like to set minDate and maxDate according to the datepicker inputs.
Below my idea/code so far, which doesn’t work yet. I don’t how to get the right values and set it as min/maxDates. Can anyone help me out? Note: I’m using the ‘date time picker’ field and the date format is Y-m-d H:i:s
(function($) {
acf.add_filter('date_time_picker_args', function( args, $field ){
// startdate
if($field.attr('data-key') == 'field_589ad500b80f7') {
//args.maxDate = '?'; // enddate value
}
// enddate
if($field.attr('data-key') == 'field_58762d1ffaeb8') {
// args.minDate = '?'; // startdate value
}
return args;
});
})(jQuery);
I don’t have an exact solution for you. I have this, that shows how to set the date of one date picker based on another https://support.advancedcustomfields.com/forums/topic/autocomplete-end-date-when-start-date-is-selected-in-jquery-date-picker/
For the exact solution you need to look at the documentation for the jQuery datepicker field. There is a good example of what you want here http://stackoverflow.com/questions/16267903/jquery-datepicker-changing-mindate-and-maxdate-on-the-fly