Rotate your device to portrait mode

Limit past dates on Gravity Forms date selector

If you are using Gravity Forms, and have a few dates that you need to limit the choices of, using a combination of a few bits of code, you can easily limit past or previous days.

The code allows you to limit past / previous days or dates, and also choose the amount of days in advance that the user can select and also places the correct date format in the field.

The first think you want to do is create an HTML block in your gravity form and then place the snippet it, you will then need to adjust the #input_X_Y to suit your form and field ID, so if you form is 1, and the date field is 10, the code would be #input_1_10.

You can also adjust the minimum date by changing the +0d to any value you like, perhaps you don’t take bookings without 24/48 hours notice, so you could add +1d or +2d.

Depending on how your want your date displaying once it has been chosen, we found that without dateFormat: “dd-mm-yy”, the date was displaying as mm-dd-yy, even though we have set all our times and dates to local regional settings, so you can adjust this to suit your location and preference.

Depending on where you place your HTML block, you may also see padding or margins above or below, so if that occurs, you can move the HTML block to the start or end of the gravity form, and or tick “Disable default margins” at the bottom of the HTML block

<script>
jQuery.noConflict();
jQuery(document).ready(function($) {
$("#input_X_Y").datepicker( { 
	minDate: "+0d",
	dateFormat: "dd-mm-yy",});
} 
);
</script>

 

Creating beautiful websites since 2006

Ready when you are

Get in touch to talk about your next web project by emailing, calling us, or by filling and submitting the following form.

We look forward to hearing from you!

Emailenquiries@kinskiandbourke.com
Phone02 8004 3387

Kinski & Bourke
Copyright © 2006 — 2020

Say hello