Disable setting of focus for jQuery UI datepicker

black666 picture black666 · Aug 2, 2011 · Viewed 32k times · Source

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...

Answer

Michal Shulman picture Michal Shulman · Jun 30, 2013

set input to ReadOnly

<input type="text" id="datePicker" readonly>