Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-26-2012, 01:22 PM   PM User | #1
crmpicco
Senior Coder

 
crmpicco's Avatar
 
Join Date: Jan 2005
Location: Mauchline, Scotland
Posts: 1,091
Thanks: 15
Thanked 1 Time in 1 Post
crmpicco has a little shameless behaviour in the past
force the focus to leave a form field with jQuery in iOS

Using jQuery or something similar, is it possible to detect when a user has clicked away, effectively removed focus, from a form field in iOS? I have conventional form which has a first name, last name, address line 1, address line 2 etc.

On an iPad when you select a form field the only way to leave that form field is to select another field in the form by clicking it or by hitting the Previous or Next buttons in the keyboard pane.

As the keyboard pane is shown clicks to other non-input elements on the page are ignored, so focus remains on the form field.

Is there a way with jQuery/JavaScript (or anything else) to force the focus to leave the form field if I click away from it by clicking a non-input form element?

I have tried this sort of thing, but to no avail. Is this likely to be locked down by Apple's iOS?

Code:
$('body').on('click', function () { $('form').blur(); });
Here's an example of what I mean. In the screen below, when the focus is on the Line 1 element I can't move out of it by clicking a non-input element.

crmpicco is offline   Reply With Quote
Old 09-27-2012, 12:37 PM   PM User | #2
hdewantara
Regular Coder

 
hdewantara's Avatar
 
Join Date: Aug 2009
Location: Jakarta, Indonesia.
Posts: 287
Thanks: 4
Thanked 39 Times in 39 Posts
hdewantara is an unknown quantity at this point
Untested, but maybe you should install that to another CLICKABLE(?) element e.g. a link, an input, etc rather than the body.
Code:
$('#dummy').on('click', function (e) { 
  e.preventDefault();
  $('form').blur(); 
});
...
<a id="dummy" href="#">&nbsp;</a>

Last edited by hdewantara; 09-27-2012 at 12:41 PM..
hdewantara is offline   Reply With Quote
Reply

Bookmarks

Tags
apple, ios, ipad, javascript, jquery

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:43 PM.


Advertisement
Log in to turn off these ads.