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.

How to modify datepicker settings?

  1. I was using an ID selector to modify each of my date fields on a form in my JavaScript:

    if ($('#input_6_16').length) {
        $('#input_6_16').datepicker({minDate: '+0', gotoCurrent: true, prevText: '', showOn: 'both', buttonImage: '/wordpress/wp-content/plugins/gravityforms/images/calendar.png', buttonImageOnly: true});
      }

    And I was including the image because I had read in another thread that overriding the picker required including the image again. And this way works great!

    But this is getting somewhat tedious to have to do for each form and field (6+ forms some with 2+ date fields). I was hoping I could use a class selector instead to modify the UI datepicker for each date on a form:

    if ($('.ff-date input.datepicker').length) {
        $('.ff-date input.datepicker').datepicker({minDate: '+0', gotoCurrent: true, prevText: '', showOn: 'both', buttonImage: '/wordpress/wp-content/plugins/gravityforms/images/calendar.png', buttonImageOnly: true});
      }

    Then for each date field on a form I add ff-date in the CSS class advanced setting. But this doesn't seem to work at all.

    Is it not possible to modify a datepicker using class selectors? Do you have to use ID selectors?

    Thanks

    Posted 12 years ago on Wednesday March 21, 2012 | Permalink
  2. I finally came up with a solution that uses the UI datepicker methods to update the setting and then refresh the object. I don't think I could reference the datepicker class because it was being added on the fly as well. This will work nicely across multiple forms.

    // Only allow future dates via the calendar for date fields found on forms.
      if ($('.ff-date input').length) {
      	$('.ff-date input').datepicker("option", "minDate", "+0").datepicker("refresh");
    
      }
    Posted 12 years ago on Thursday March 22, 2012 | Permalink
  3. Thanks for posting your solution.

    Posted 12 years ago on Friday March 23, 2012 | Permalink
  4. Thanks for sharing +1. I'm trying to implement this but having trouble figuring out where to place it. I've put the following in my header.php:

    <script type="text/javascript">
    // Only allow future dates via the calendar for date fields found on forms.
      if ($('.ff-date input').length) {
      	$('.ff-date input').datepicker("option", "minDate", "+0").datepicker("refresh");
    
      }
      </script>

    Should I do this in functions.php instead? Would really appreciate some direction on this, thank you!

    Posted 12 years ago on Thursday July 19, 2012 | Permalink
  5. David Peralty

    Here is a great article we have on where code goes:
    http://www.gravityhelp.com/documentation/page/Where_Do_I_Put_This_Code%3F

    Also, make sure your date picker has a ff-date class.

    Posted 12 years ago on Thursday July 19, 2012 | Permalink
  6. Thank you, David!

    Posted 12 years ago on Thursday July 19, 2012 | Permalink

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