The first element in my jQuery UI Dialog is an input, which when selected opens a datepicker...
How can I disable this input from being selected first?
Very simple, just trigger the blur
event on the input elements when the dialog box opens.
$("#dialog").dialog({
open: function(event, ui) {
$("input").blur();
}
});
NOTE: For more in-depth solution to this problem, read this answer too.
Add the following code before you call dialog. This will clear out the autofocus code. It works for me in jquery 2.0.3.
$.ui.dialog.prototype._focusTabbable = function(){};
JQuery sets the autofocus on the first input that is found.
So play it sneaky by creating a "fake" input at the first line of your dialog like that:
<input type='text' size='1' style='position:relative;top:-500px;' />
So your input will be out of the window and have the focus. Problem solved for me ;p
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