Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to remove Autofocus in ui-dialog [duplicate]

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?

like image 906
Josh Avatar asked Mar 22 '12 04:03

Josh


3 Answers

Very simple, just trigger the blur event on the input elements when the dialog box opens.

$("#dialog").dialog({
    open: function(event, ui) {
        $("input").blur();
    }
});

Check it out here

Solution with datepicker

NOTE: For more in-depth solution to this problem, read this answer too.

like image 124
Starx Avatar answered Oct 22 '22 12:10

Starx


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(){};
like image 36
LaXDragon Avatar answered Oct 22 '22 11:10

LaXDragon


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

like image 34
kts Avatar answered Oct 22 '22 10:10

kts