PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Limit the past on date field

  1. Hi,

    Is it possible to have users select a future date only? I have a schedule a consultation date field and a couple users already added past dates, what doesn't make any good sense, but I need to make sure that doesn't happen.

    Is also possible to limit the future years? I would like to show from current date up to 2 years maximum (currently my date field allows a 1912-2032 selection range).

    Thx in advance

    Posted 11 years ago on Wednesday August 1, 2012 | Permalink
  2. I found out how to handle this. Just in case someone is facing the same issue just go to your gravity forms plugin folder > js > jquery-ui > ui.datepicker.js and change the minDate and maxDate.

    eg:
    minDate: 0, // this will set to the current date
    maxDate: +90, // this will let users choose up to 90 days from the current date

    cheers

    Posted 11 years ago on Wednesday August 1, 2012 | Permalink
  3. You should never modify any of the plugin files. You will lose those changes when the plugin is updated. Here is documentation on how to add those same limits without changing any plugin files.

    http://jqueryui.com/demos/datepicker/#min-max

    There is a small snippet of JavaScript to add to the pages where the form with the datepicker exists. Let us know if you need help implementing this the correct way to prevent future problems. Thank you.

    Posted 11 years ago on Wednesday August 1, 2012 | Permalink
  4. Hi, I used the following code to limit the dates to between 65 and 14 years in the past:

    <script>
        jQuery(function ($) {
            $( "#input_1_4" ).datepicker({ minDate: "-65Y", maxDate: "-14Y" });
        });
    </script>

    But then the year dropdown doesn't show at all. And it seems the UI on the gravityform is a bit messed up. Any idea what I'm doing wrong?

    Posted 11 years ago on Wednesday August 8, 2012 | Permalink
  5. SOLVED! Used the following code:

    <script>
        jQuery(function ($) {
            $("#input_1_4").datepicker({
                changeMonth: true,
                changeYear: true,
                dateFormat: 'M/dd/yy',
                yearRange: '-100:-14',
                defaultDate:'-14y'
            });
        });
    </script>

    Thanks anyway!

    Posted 11 years ago on Wednesday August 8, 2012 | Permalink
  6. http://jqueryui.com/demos/datepicker/#min-max

    There is a small snippet of JavaScript to add to the pages where the form with the datepicker exists. Let us know if you need help implementing this the correct way to prevent future problems. Thank you.

    (Raises Hand) I need help here!

    I need dates set to the day after the user selects and end in December 2014

    I read the page you've linked. Please let me know what code to add and where to add it.

    Thank you!

    Posted 11 years ago on Saturday September 1, 2012 | Permalink
  7. @goldenimage, please begin a new topic for your issue as it is unrelated to the topic here. You're going to need to calculate tomorrow's date and store that. This will probably be code added to your theme's functions.php.

    If the December 2014 date is always the same you can just save that in an admin-only field.

    Posted 11 years ago on Sunday September 2, 2012 | Permalink

This topic has been resolved and has been closed to new replies.