1

I'm able to load and reopen jQueryUI Dialogs with a Datepicker as the first element in all browsers I've tried ... except IE 9. If a Datepicker is the first element to receive focus when the Dialog opens, the Datepicker will auto launch. I'm able to suppress this behavior in FireFox and Chrome. IE 9 still launches the Datepicker on creation.

My open and close function for the Dialog are:

open: function (event, ui) {
   $('#Date').blur();  // kill the focus
   if ($('#Date').hasClass('hasDatepicker')) {
        $("#Date").datepicker('enable');
   }
   else {
      $("#Date").datepicker();
   }
},
close: function (event, ui) {
    $("#Date").datepicker('disable');
}

Here is the 'click' code

var dialogs = {};
 $('#clicker').click(function (e) {
     if (!dialogs['dlg']) {
        loadAndShowDialog('dlg');
      } else {
         dialogs['dlg'].dialog('open');
      }
  });

var loadAndShowDialog = function (id) {
 dialogs[id] = $('#dlg').clone().find('#ChangeMe').attr('id', 'Date').end()
      .appendTo(document.body)
      .dialog({ // Create the jQuery UI dialog
          title: 'Testing',
          modal: true,
          resizable: true,
          draggable: true,
          width: 300,
          open: see above
          close: see above

        };

jsfiddle showing this IE9 problem http://jsfiddle.net/stocksp/DdRLp/8/

What can I do to get IE to behave, short of not placing the Datepicker as the first element?

1 Answer 1

1

I don't have IE9 available at home so give this a try: http://jsfiddle.net/DdRLp/10/

I added a class to the datepicker input to make it easier to grab.

$(function() {

$(document).on("dialogcreate", "#dlg", function() {
    $(".date_picker").datepicker();
    $(".date_picker").datepicker("disable");
});

var dialogs = {};
$('#clicker').click(function(e) {
    if (!dialogs['dlg']) {
        loadAndShowDialog('dlg');
    } else {
        dialogs['dlg'].dialog('open');
    }
});
var loadAndShowDialog = function(id) {

    dialogs[id] = $('#dlg').clone().find('#ChangeMe').attr('id', 'Date').end().appendTo(document.body).dialog({ // Create the jQuery UI dialog
        title: 'Testing',
        modal: true,
        resizable: true,
        draggable: true,
        width: 300,
        open: function(event, ui) {
            $("div#dlg form input").blur(); //takes focus off inputs 
            $(".date_picker").datepicker("enable");
        },
        close: function(event, ui) {
            $(".date_picker").datepicker("disable");
        }
    });

};

});
1
  • Excellent, much nicer than my stab in the dark!
    – Pablo
    Commented Jan 28, 2012 at 3:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.