Cordova/Phonegap iOS focus on textfield using JavaScript or jQuery

I was working on Cordova app for one of our client, Curious. Based on a user action we had to focus on a certain textfield. 

Things worked fine on the mobile site but when the same code was ported to Cordova everything except the focus worked. On investigation what was surprising was querying for the currently focused element using jQuery returned the same textfield in question.

$(":focus")

Which meant that even though the textfield was focused for some odd reason the cursor and the keyborad where not showing up. I figured there might be some restriction by iOS itself and on some googling I found out indeed that was the case and a solution on stackoverflow http://bit.ly/LRluga

You had to configure the app for it to be able to show the keyboard through JavaScript. You can add that either in the generated ObjectiveC code after the WebView has loaded.

    theWebView.keyboardDisplayRequiresUserAction = NO;

Or you can configure it in www/config.xml as

   <preference name="KeyboardDisplayRequiresUserAction" value="false">
About CauseCode: We are a technology company specializing in Healthtech related Web and Mobile application development. We collaborate with passionate companies looking to change health and wellness tech for good. If you are a startup, enterprise or generally interested in digital health, we would love to hear from you! Let's connect at bootstrap@causecode.com
Have you subscribed to our blogs and newsletter? If not, what are you waiting for?  Click Here

Leave a Reply

Your email address will not be published. Required fields are marked *

SUBSCRIBE!

Do you want to get articles like these in your inbox?

Email *

Interested groups *
Healthtech
Business
Technical articles

Archives