문제

I have a jquery datepicker problem: there are 2 input fields. (#date1 and #date2) These inputs opens, pops up the datepicker's calendar panel. When I pick up a date from the first input, the cursor jumps automatically to the second input, and autoopen the second input's calendar panel. (you can't choose future dates), At the #date2, only the previous arrow button works for the prevoius months and days. When I first click on the prev button, the whole calendar window "blinks" one time, - I think - the calendar loaded again, and that effect results the calendars blinking. It's very annoying you have to click again to the prev button to see the previous months. So, if you click again to the prev arrow, it works fine. How could I terminate this "blinking"?

$('#date1').datepicker({
    maxDate: '+0d',
    changeMonth: true,
    numberOfMonths: 1,
     onClose: function( selectedDate ) {
        $('#date2').datepicker( "option", "minDate", selectedDate );
        $('#date2').focus();
    }
  });

$('#date2').datepicker({
    maxDate: '+0d',
    changeMonth: true,
    numberOfMonths: 1,
    onClose: function( selectedDate ) {
        $( '#date1' ).datepicker( "option", "maxDate", selectedDate );
    }
});


 <div class="tableoptions">
        <span class="field">  
            <label for="fromdate">From:</label>
            <input id="date1" name='fromdate' type="text" class="width75" /> 
        </span>
        <span class="field">
            <label for="todate">To:</label>
            <input id="date2" name='todate' type="text" class="width75" /> 
        </span>
        <input type ="submit" class="dp_submit" value="Date Filter">
 </div>
도움이 되었습니까?

해결책

Looks like there's some sort of race condition going on here causing the problem. Adding a small delay before focusing on the second datepicker seems to fix it.

onClose: function (selectedDate) {
    $('#date2').datepicker("option", "minDate", selectedDate);
    setTimeout(function () {
        $('#date2').focus();
    }, 100);
}

jsFiddle example

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top