Disable setting of focus for jQuery UI datepicker

Viewed 34818

There is an option with the jQuery UI datepicker to only open the datepicker when a button image is clicked. See the following for an example:

http://jqueryui.com/demos/datepicker/#icon-trigger

The problem is that the focus is in the textfield as soon as the datepicker opens. Is it possible to disable the setting of the focus?

When using a page like the above on a mobile device like an iPhone, the keyboard pops up because the textfield gains the focus. This is not really userfriendly since you have to close the keyboard to actually get to the datepicker and use it...

10 Answers

This is an older question, but if you stumble on it looking for a solution to the same problem I believe the solution in modern browsers is to use inputmode="none" in the HTML input tag:

<input type="text" ... inputmode="none" />

I haven't tested it extensively, but it's worked well in Android with the setups I've used.

I've been experiencing the same problem on an application I am working on. I commented out these lines from my jQuery file to prevent it from automatically setting focus on the textfield immediately after clicking on my calendar icon. It worked for my application.

if ( $.datepicker._shouldFocusInput( inst ) ) {
    inst.input.focus();
}
Related