Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQueryUI Dialog/Datepicker Auto-Opens

I currently have a dialog box with two inputs as its content (with the two inputs using .datepicker()). When I open dialog box, the first input becomes the focus and the first datepicker automatically appears. I have tried hiding the div and blurring the input, but that causes the datepicker to no longer appear on focus.

Ideally, I want to be able to the following:

  • Open the dialog box (with no datepickers showing).
  • Click in the first input and have the datepicker show.

Here is my current code:

JAVASCRIPT:

$("#to").datepicker({
      onClose: function (selectedDate) {
         $("#from").datepicker("option", "minDate", selectedDate);
      }
    });

    $("#from").datepicker({
     onClose: function (selectedDate) {                            
         $("#to").datepicker("option", "maxDate", selectedDate);
    }
});


$("#settingsDialog").dialog({
     autoOpen: false,
    open: function (event, ui) {
                     if ($(".ui-datepicker").is(":visible"))
                         $(".ui-datepicker").hide();

                     $("#to").blur();
                     $this.focus().click();
                 },
     close: function () {
         $(this).dialog("close");
     }
});

I have also made a jsfiddle demo: http://jsfiddle.net/ARnee/19/

I have searched online for a solution, and found similar questions, but none that seem to help. Could anyone assist me?!

EDIT:

The browser I am using is Chrome.

like image 683
Dom Avatar asked Jan 04 '13 23:01

Dom


2 Answers

Try setting the tabindex attribute on the inputs containing the datepicker to -1.

<input type="text" id="to" tabindex="-1" />

EDIT:

<input id="to" type="text" tabindex="-1" />
<input id="from" type="text" tabindex="-1" />  

DEMO: http://jsfiddle.net/ARnee/32/

like image 67
kayz1 Avatar answered Sep 21 '22 10:09

kayz1


Can stick a dummy input in dialog that has no height so won't be seen. Place it before the datepicker fields

<input style="height:0px; border:none"/>

DEMO: http://jsfiddle.net/ARnee/20/

like image 33
charlietfl Avatar answered Sep 23 '22 10:09

charlietfl