Search code examples
jquery-uicalendarjquery-ui-datepicker

Why next button open and close my calendar?


I'm using two datepickers in my project, start date and end date. The first one open the second calendar with show method.

I notice the next button on the second calendar close and reopen the calendar.
I want to avoid this "open/reopen" issue.

What am i doing wrong ?

HTML

<input id="startDate" type="text" /><br />
<input id="endDate" type="text" /><br />

Javascript

$(function(){
    $('#startDate').datepicker({
        dateFormat: 'dd-mm-yy',
        onClose: function (dateText, inst) {
            $('#endDate').datepicker("show");
        }
    });

    $('#endDate').datepicker({
        dateFormat: 'dd-mm-yy'
    });

});

Please check my code : http://jsfiddle.net/8w8v9/3078/


Solution

  • I have a dirty solution, I can only suppose what happen: you show the "endDate" datepicker before is totaly closed the first one and this creates some conflict.

    The JSFiddle

    $(function() {
    
      $('#startDate').datepicker({
        dateFormat: 'dd-mm-yy',
        onClose: function(dateText, inst) {
          setTimeout(function() {
            $('#endDate').datepicker('show');
          }, 50);
        }
      });
    
      $('#endDate').datepicker({
        dateFormat: 'dd-mm-yy'
      });
    
    });