Restricting dates under calendar [RESOLVED]

Hi,

Hoping for some help please. Want to restrict dates that can be selected from today’s date for up to 30 days.

Hoping for some code to add to functions php file. Looked online and it appears might also need to add code elsewhere in addition, which is beyond me…help?

Regards
Steve

Hi Steve, the easiest is most reliable way to do this is with Gravity Forms Limit Dates by Gravity Wiz. In fact, we covered this specific use-case here:

https://gravitywiz.com/how-to-require-a-future-or-past-date-with-gravity-forms-date-picker/

If you prefer to muck about in code, Gravity Forms does have a JS snippet which can handle this specific bit of functionality:

If you go that route, you can save yourself a little hassle with another Gravity Wiz resource that lets you install form-specific Javascript directly in your form settings:

https://gravitywiz.com/gravity-forms-custom-javascript/

1 Like

Thanks David.

Decided to go for programming so I uploaded the Gravity Froms Custom Java Script plugin.

Under form settings of each form now have custom java script box. In the box I’ve added the following code, disabling past dates and making sure the field ID is correct, but you can still select a past date, please help:

gform.addFilter(  'gform_datepicker_options_pre_init' ,  function ( optionsObj, formId, fieldId ) {
	// Apply to field 2 only 
	if ( fieldId == 2 ) {
		optionsObj.minDate = 0;
	}
	return optionsObj;
});

Do you have a URL where I could see the form?

Hi David,

Thanks.

Regards
Steve

Are you sure the field ID, 2, in the code snippet is correct? Inspecting the “Renewal or cover start date” field using the browsers developer tools reveals it has the ID of 1.

1 Like

All sorted thanks. Please close.

© 2008 - 2019. Gravity Forms is a project by Rocketgenius Inc.