Restrict to specific dates
in Gravity Forms datepicker
Have you ever felt the need to disable certain dates/times within the date-picker of Gravity Forms?
You cannot do that in the back-end.
There are some plugins promising that, but this plugin only allows you to restrict the range to fixed dates. That’s not very useful when you want to restrict e.g. to today and 1 year ahead.
You can insert a code in the header of the page, like this:
jQuery(document).ready(function($) {
$(".datepicker").datepicker({ minDate: 0 });
});
But hey, did you notice? Your calendar button (the small icon next to the input field) disappears! So, we also have to add the path to the button image again (make sure the path is correct)
jQuery(document).ready(function($) {
$( "#input_6_3-0" ).datepicker({ buttonImage: 'images/calendar.gif', minDate: '+1d' });
});
Another Simple Solution
Even with the above code, sometimes the calendar button just will not show up, although you made absolutely sure the path to the image file is correct. I haven’t yet found out why that is. In that case you have to resort to editing a core file in Gravity Forms:
wp-content/plugins/gravityforms/js/datepicker.js
Don’t worry, it’s very simple, change this (on line 9 and 10):
yearRange: '-100:+20',
showOn: 'focus',
to this:
yearRange: '0:+1',
minDate: '+1w',
maxDate: '+1y',
showOn: 'focus',
It’s pretty self explanatory: a user can only select the current year and the next, only a date 1 week from today, and the maximum date a user is able to select is 1 year from today.
Of course this file will be overwritten every time you update Gravity Forms, but because the change is so simple (less than 1 minute work), you’ll just have to make a note that you should apply the above change after an update.
Other Tips & Tricks
Online Payments in Cambodia
Are online payments possible in Cambodia? Yes, they are. Read what we recommend for Cambodian eCommerce businesses.