# Restricting dates under calendar \[RESOLVED\]

**URL:** <https://community.gravityforms.com/t/restricting-dates-under-calendar-resolved/2917>\
**Category:** Get Help\
**Tags:** gform\_datepicker\_options\_pre\_init, gravity-wiz\
**Created:** [October 3, 2019, 1:51pm UTC](https://community.gravityforms.com/t/restricting-dates-under-calendar-resolved/2917 "2019-10-03T13:51:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![user5d946cb97251d498](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/user5d946cb97251d498/32/1056_2.png) [@user5d946cb97251d498](https://community.gravityforms.com/u/user5d946cb97251d498)\
**Post date:** [October 3, 2019, 1:51pm UTC](https://community.gravityforms.com/t/restricting-dates-under-calendar-resolved/2917/1 "2019-10-03T13:51:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![david](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/david/32/2517_2.png) [@david](https://community.gravityforms.com/u/david)\
**Post date:** [October 3, 2019, 3:56pm UTC](https://community.gravityforms.com/t/restricting-dates-under-calendar-resolved/2917/2 "2019-10-03T15:56:49Z")

</div>

Hi Steve, the easiest is most reliable way to do this is with [Gravity Forms Limit Dates](https://gravitywiz.com/documentation/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/](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:

> **[gform\_datepicker\_options\_pre\_init - Gravity Forms Documentation](https://docs.gravityforms.com/gform_datepicker_options_pre_init/#9-disable-past-dates)**
>
> This filter can be used to modify the options used to initialize a fields datepicker.

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/](https://gravitywiz.com/gravity-forms-custom-javascript/)

---

<div class="post-metadata">

**Author:** ![user5d946cb97251d498](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/user5d946cb97251d498/32/1056_2.png) [@user5d946cb97251d498](https://community.gravityforms.com/u/user5d946cb97251d498)\
**Post date:** [October 4, 2019, 11:48am UTC](https://community.gravityforms.com/t/restricting-dates-under-calendar-resolved/2917/3 "2019-10-04T11:48:31Z")

</div>

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:

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

```

---

<div class="post-metadata">

**Author:** ![david](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/david/32/2517_2.png) [@david](https://community.gravityforms.com/u/david)\
**Post date:** [October 7, 2019, 5:39pm UTC](https://community.gravityforms.com/t/restricting-dates-under-calendar-resolved/2917/4 "2019-10-07T17:39:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![user5d946cb97251d498](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/user5d946cb97251d498/32/1056_2.png) [@user5d946cb97251d498](https://community.gravityforms.com/u/user5d946cb97251d498)\
**Post date:** [October 7, 2019, 6:32pm UTC](https://community.gravityforms.com/t/restricting-dates-under-calendar-resolved/2917/5 "2019-10-07T18:32:56Z")

</div>

Hi David,

Thanks.

> **[Leaseholders Improvements and Contents Quote - EmberJD](https://www.emberjd.com/request-quote/leaseholders-improvements-contents-quote/)**
>
> ℹ Important please read

Regards  
Steve

---

<div class="post-metadata">

**Author:** ![richardw8k](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/richardw8k/32/2354_2.png) [@richardw8k](https://community.gravityforms.com/u/richardw8k)\
**Post date:** [October 8, 2019, 1:53pm UTC](https://community.gravityforms.com/t/restricting-dates-under-calendar-resolved/2917/6 "2019-10-08T13:53:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![user5d946cb97251d498](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/user5d946cb97251d498/32/1056_2.png) [@user5d946cb97251d498](https://community.gravityforms.com/u/user5d946cb97251d498)\
**Post date:** [October 9, 2019, 12:12pm UTC](https://community.gravityforms.com/t/restricting-dates-under-calendar-resolved/2917/7 "2019-10-09T12:12:23Z")

</div>

All sorted thanks. Please close.

---

<div class="post-metadata">

**Author:** ![chrishajer](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/chrishajer/32/88_2.png) [@chrishajer](https://community.gravityforms.com/u/chrishajer)\
**Post date:** [October 9, 2019, 6:27pm UTC](https://community.gravityforms.com/t/restricting-dates-under-calendar-resolved/2917/8 "2019-10-09T18:27:05Z")

</div>

Closed on October 9, 2019, 6:27pm UTC


