Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery UI Datepicker - Why does the 2nd datepicker disappear onfocus?

I have two input elements that function as jQuery UI datepickers. After you make a selection on the first datepicker element it should automatically focus on the second datepicker element and show the calendar, allowing you to easily and quickly make a choice.

For whatever reason the second datepicker/calendar is appearing for a moment and then disappearing. I am not sure why it is disappearing; can anyone offer me an explanation as to why it's disappearing and a possible solution?

Currently utilizing the following libraries: jQuery 1.8.3, jQuery UI 1.9.2

Here's the code I am currently using:

<ul class="fields">
    <li><label>Date picker #1</label>
        <input type="text" class="date-picker-1" />
    </li>
    <li><label> Date picker #2</label>
        <input type="text" class="date-picker-2" />
    </li>
</ul>

$('input.date-picker-1').datepicker({
    constrainInput: true,
    hideIfNoPrevNext: true,
    onSelect: function () {
        $(this).closest('.fields')
           .find('.date-picker-2').datepicker('show');
    }
});

$('input.date-picker-2').datepicker({
    onFocus: 'show'
});

Here's a fiddle: http://jsfiddle.net/B78JJ/

If any other information would be helpful please feel free to ask and I'll be happy to help out.

like image 597
kyle.stearns Avatar asked Oct 05 '22 08:10

kyle.stearns


1 Answers

It seems a focus timing issue, the quick workaround is to use a small timeout:

$('input.date-picker-1').datepicker({
    constrainInput: true,
    hideIfNoPrevNext: true,
    onSelect: function () {
        var dees = $(this);
        setTimeout(function() { 
           dees.closest('.fields').find('.date-picker-2').datepicker('show');
        }, 100);
    }
});

See working fiddle

like image 64
Nelson Avatar answered Oct 12 '22 01:10

Nelson