I am displaying a jQuery UI dialog window that contains a jQuery UI datepicker control in it. The problem is that the first form field on the dialog window is the datepicker and thus it receives focus when the window opens up which in turn causes the datepicker window to automatically open. I don't want this to occur.
I have tried calling
$('#Date').datepicker('hide')
in then open function of the dialog window and also after the code that makes the dialog open but it doesn't work as when that code is reached, the datepicker window isn't open yet.
How can I make it so that the datepicker window doesn't open when the dialog window shows up but still have it open when the user clicks on the input?
You could use the icon trigger: http://jqueryui.com/demos/datepicker/#icon-trigger
And, if needed, prevent the user from typing in a date.
I created a fiddle of a dialog with a datepicker and couldn't duplicate the issue in FF or Chrome. Got it to happen in IE.
http://jsfiddle.net/458bM/2/
$(".datepicker").datepicker({
dateFormat: 'yy-mm-dd '
});
$(".datepicker").datepicker("disable");
$("#dialog").dialog({
width: 400,
modal: true,
open: function(event, ui) {
$(".datepicker").datepicker("enable");
}
});
Based on previous answer: How to blur the first form input at the dialog opening
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With