I have a datepicker which is used within the jQuery dialog object. The source of the dialog\'s content is loaded using .load()
. Within the dialog I created a sc
It's just dialog focus: api.jqueryui.com/dialog/
Upon opening a dialog, focus is automatically moved to the first item that matches the following
- The first element within the dialog with the autofocus attribute
- The first :tabbable element within the dialog's content
- The first :tabbable element within the dialog's buttonpane
- The dialog's close button
- The dialog itself
A solution is to use the autofocus
attribute on other fields than datepicker
.
When you put the datepicker field at the beginning of the dialog it is opened automatically. You can place a hidden input at the beginning of the dialog.
<input type="text" style="width: 0; height: 0; top: -100px; position: absolute;"/>
The reason is : your first item inside modal form is the datepicker text field, and when the modal is fired, the active control is the one who contains the datepicker.
I found out two alternative solutions:
Change the order of your fields. Avoid the one with datepicker to stay in first place.
Do not set datepicker to the field in a separate piece of code, do it inside the function that opens the dialog (right after openning $("#dialog").dialog("open");
).
For some reason the calendar stopped having this behavior when I filled in the animation option in the initializer:
showAnim: Drop
The reason picker opens by itself, is that the input field stays focused after you open picker for the first time.
You need to blur it:
$input.datepicker({
onClose: function(dateText) {
$(this).trigger('blur');
}
});
I had this exact problem and solved it with only a slight variation on tvanfosson's technique. For some reason I had to manually attach the "click" event to the datepicker field as below.
$('#dialog').dialog({
open: function(event, ui) {
$(ui).find('#date').datepicker().click(function(){
$(this).datepicker('show');
});
},
close: function(event,ui) {
$(ui).find('#date').datepicker('destroy');
}});
(Sorry--I would've preferred to post this as a comment to tvanfosson's post but don't have the requisite rep.)