I’m working on a way to create a booking calendar for a campsite with Gravity Forms which has all of the functionality I need apart from one small issue with the check-in/check-out dates.
I currently have two date picker fields set up, one for check-in and one for Check-out, and I have a calculation field that is able to work out the range of the dates and work out a price/night. All good so far.
The difficulty comes when trying to limit dates on the check-in and check-out dates.
I need to be able to restrict dates in a particular way. Bookings can only be made on weekends and some bank holidays (causing a bit of a problem - as you can’t simply restrict particular days of the week using the ‘gform_datepicker_options_pre_init’ function).
This is as far as I can get with this function, I’m able to restrict the dates to weekends only, but I’m unable to unset certain dates, and also limit the maximum date of the check-out field.
gform.addFilter( 'gform_datepicker_options_pre_init', function( optionsObj, formId, fieldId ) {
if ( formId == 1 && fieldId == 1 ) {
optionsObj.firstDay = 1;
optionsObj.beforeShowDay = function(date) {
var day = date.getDay();
return [(day == 0 || day == 6)];
};
}
return optionsObj;
});
gform.addFilter( 'gform_datepicker_options_pre_init', function( optionsObj, formId, fieldId ) {
if ( formId == 1 && fieldId == 1 ) {
optionsObj.minDate = 0;
optionsObj.onClose = function (dateText, inst) {
jQuery('#input_1_2').datepicker('option', 'minDate', dateText).datepicker('setDate', dateText);
};
}
return optionsObj;
});
In addition to this, the checkout field needs to be on the same weekend as the check-in date that was specified. So for example you can’t have a check-in date of Saturday 13th March and a checkout date of Saturday 20th March.
I have looked around and whilst the documentation here (gform_datepicker_options_pre_init - Gravity Forms Documentation) does go some way in restricting dates, it doesn’t do everything I want it to do. Particularly being able to restrict certain days of the week and then enable particular days, and then limit the check-out date based on the check-in date.
I’ve also found a plugin here (Restrict Dates In Gravity Forms - Gravitymore.com), but my main concern is making sure the check-out date is dependent on the check-in date. It’s a bit of a worry that I seem to be trying to shoehorn in a key function of a booking form!
Many thanks for any help to help get this figured out!