1

My clients who need to enter start and end dates (well into the future) find it useful if pop-up calendar 2 starts at the date set by popup calendar 1 (and not before).

For years the code below has worked, on several different Web sites:

    $( "#start" ).datepicker({ dateFormat: 'yy-mm-dd' });  
    $( "#end" ).datepicker({  
        dateFormat: 'yy-mm-dd',  
        beforeShow: function()  {  
            dt = $( "#start" ).datepicker( 'getDate' );  
            return { minDate: dt }; // a JS object - dt could be 'null' (which is OK)

I cannot get it to work using current versions of jQuery UI. I have tried some general beforeShow solutions suggested on this Web site, but none of them solves my problem.

Can anyone suggest a solution? Or is there a solution which uses even less code than the above?

5
  • There's nothing wrong in the code posted (though dt should probably be a local variable), the problem is elsewhere. Could you reproduce this in a MCVE? Commented Nov 11, 2015 at 16:03
  • An MCVE won't help. The code is fine. It works at this moment on several Web sites of mine, using older versions of jQuery UI. But it won't work with current versions of jQuery UI. I need to know why, and what I can do to get the code working again. Commented Nov 12, 2015 at 7:47
  • Why won't an MCVE help? Diagnosing an issue you can reproduce is a lot easier than one you can't Commented Nov 12, 2015 at 9:44
  • An MCVE won't help because the only difference between the code which does what it should, and the code which fails, is that the HTML head of the Web page where the works invokes an older version of JQuery UI, and the HTML head of the Web page where it doesn't work invokes a current version of jQuery UI. Commented Nov 12, 2015 at 16:39
  • That actually sounds very helpful. Debugging the two side-by-side should let one see exactly what and how has changed in the updated libraries Commented Nov 12, 2015 at 18:37

2 Answers 2

2

I have wasted everyone's time. The code as typed above works just as it should, in the very latest version of jQuery UI. The code which wasn't working used a different date format. I didn't think that small difference mattered, but I have now discovered that the date format is not just a display format, but is used by the widget's methods.

For what it is worth, because I am developing a summer holiday rental site, and designing mobile first, I thought that the display date could dispense with the year. Maybe it can — but the dateFormat option is not just a display date. The widget needs either the default dateFormat, or for a custom dateFormat to be defined with a year!

Sign up to request clarification or add additional context in comments.

Comments

0

When i see it right you have syntaxError in your code.

Try putting this code and tell me if it worked:

 $( "#start" ).datepicker({ dateFormat: 'yy-mm-dd' });  
 $( "#end" ).datepicker({  
     dateFormat: 'yy-mm-dd',  
     beforeShow: myFunction
 });

function myFunction(){  
     dt = $( "#start" ).datepicker( 'getDate' );  
     return { minDate: dt };
}

2 Comments

So far as I know, using anonymous functions instead of separate named functions is not only NOT a syntax error, but a coding plus!
This is NOT an answer! The code works perfectly as it is, on several Web sites (in private administrative areas).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.