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 can I remove past years from the date picker?

  1. iamthez
    Member

    My client sells tickets/cruises, that sort of thing. Obviously, she can't sell them for years that have passed... Is there a way to remove past years from the date picker?

    Posted 12 years ago on Monday July 30, 2012 | Permalink
  2. David Peralty

    This is the datepicker that we use:
    http://jqueryui.com/demos/datepicker/

    Over on the right hand side, there are details on how to restrict the dates under Examples. You would want to put your JavaScript code for this in the header.php of your theme.

    Posted 12 years ago on Monday July 30, 2012 | Permalink
  3. The datepicker is straight from the jQuery UI library so you can pass parameters in your theme header or script files to modify it.

    http://docs.jquery.com/UI/API/1.8/Datepicker

    This is probably what you're looking for

    http://stackoverflow.com/questions/1786411/jquery-datepicker-to-prevent-past-date

    $("#datepicker").datepicker({ minDate: 0 });
    Posted 12 years ago on Monday July 30, 2012 | Permalink
  4. iamthez
    Member

    I've tried a few things, but none of them seem to work. Can anyone tell me what I'm doing wrong? Example: http://directconnexiontravel.com/?page_id=25

    Posted 12 years ago on Monday July 30, 2012 | Permalink
  5. David Peralty

    Can you try the following:

    $(document).ready(function () {
    		$(".hasDatepicker").datepicker({ minDate: 0+ })
    	});
    Posted 12 years ago on Monday July 30, 2012 | Permalink
  6. iamthez
    Member

    Doesn't seem to make any difference for me...

    Posted 12 years ago on Monday July 30, 2012 | Permalink
  7. You have a syntax error in the JavaScript you pasted into the head:

    Timestamp: 7/31/2012 1:56:26 AM
    Error: SyntaxError: syntax error
    Source File: http://directconnexiontravel.com/?page_id=25
    Line: 39, Column: 47
    Source Code:
      $(".hasDatepicker").datepicker({ minDate: 0+ })

    You will also soon have a "$ is not defined" error because $ is reserved for Prototype in WordPress. Please try this version:

    <script type="text/javascript">
    var $j = jQuery.noConflict();
    $j(document).ready(function () {
    	$j(".hasDatepicker").datepicker({ minDate: '0' })
    });
    </script>

    There seems to be lots of conflicting information online of how to format the minDate:
    http://stackoverflow.com/questions/1786411/jquery-datepicker-to-prevent-past-date

    Other variations of this line you can try:

    [js]
    	$j(".hasDatepicker").datepicker({ minDate: +0 })
    [js]
    	$j(".hasDatepicker").datepicker({ minDate: 0, })
    Posted 12 years ago on Tuesday July 31, 2012 | Permalink
  8. iamthez
    Member

    I've tried all of these syntax variations, but no luck so far. Thanks for trying, though.

    Posted 12 years ago on Friday August 3, 2012 | Permalink
  9. David Peralty

    Can you try changing it to .datepicker instead of .hasDatepicker just out of curiosity?

    Posted 12 years ago on Friday August 3, 2012 | Permalink