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.

Help with Date and Time Fields

  1. AustinGolfEvents.com/Add

    My issue is hopefully pretty simple.

    1. I want the Date(year) to be from 2013-2016 instead of 1920-2014

    2. I want the time fields to only allow actual times.....Right now I can enter in 39:82 PM and the form will accept it? How do I get it so the hours go to 12 and the minutes go to 60.

    Thanks in advance for your help...........sorry I'm a newb!

    Mac

    Posted 11 years ago on Thursday May 2, 2013 | Permalink
  2. Setting the minimum and maximum year can be accomplished by adding the following code to your functions.php file:

    add_filter("gform_date_max_year", "set_max_year");
    function set_max_year($max_year){
        return 2016;
    }
    add_filter("gform_date_min_year", "set_min_year");
    function set_min_year($min_year){
        return 2013;
    }

    Now limiting the hour and minute will require adding a little jQuery to you form's page template. Using the following code will cause any hour less than 1 to change to 1 and any number greater than 12 to turn into 12. Same goes for the minute. Any number less than 0 will turn to 0 and any number greater than 59 will turn to 59.

    <script type='text/javascript'>
    jQuery(document).ready(function( $ ) {
    $('#input_3_2_1').change(function() {
    if ($(this).val() < 1){ $(this).val(1);}
    if ($(this).val() > 12){ $(this).val(12);}
    });
    $('#input_3_2_2').change(function() {
    if ($(this).val() < 0){ $(this).val(0);}
    if ($(this).val() > 59){ $(this).val(59);}
    });
    });
    </script>

    You will just need to change 'input_3_2_1' to the ID of your hour form select and 'input_3_2_2' to the ID of your minute form select. You locate their IDs by viewing the page source of your form.

    I hope this answers your questions.

    Posted 11 years ago on Thursday May 2, 2013 | Permalink