I have an issue with focusing a text field on the iPad. Where I use:
$(document).bind("click",function(event) {
alert('click');
focusTextArea();
});
The focus is set to the text area, and a keyboard appears. However when called with touchend, focusTextArea
is not called and the keyboard is not made visible. My focusTextArea
function is:
function focusTextArea() {
$('#textArea').focus();
}
Does anybody know why this occurs, and how I might be able to get this to work?
TIA,
Adam
The :focus CSS pseudo-class represents an element (such as a form input) that has received focus. It is generally triggered when the user clicks or taps on an element or selects it with the keyboard's Tab key.
To set focus to an HTML form element, the focus() method of JavaScript can be used. To do so, call this method on an object of the element that is to be focused, as shown in the example. Example 1: The focus() method is set to the input tag when user clicks on Focus button.
Unfortunately, focusing is not possible with the iPad. The only way the focus will be placed in the desired field is when the user 'clicks' on the desired field.
Update 2015-01-08:
As explained in this answer by Matt:
... iOS will only allow focus to be triggered on other elements, from within a function, if the first function in the call stack was triggered by a non-programmatic event. In your case, the call to setTimeout starts a new call stack, and the security mechanism kicks in to prevent you from setting focus on the input.
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