poperob
poperob

Reputation: 543

PhoneGap IOS Keyboard Done Key Event

I'm using JQuery Mobile within a PhoneGap IOS App. I'm currently successfully capturing the IOS Keyboard return within a search key as follows.

JS
function blah()
{
if(window.event.keyCode == 13   )
{ do something }
}

HTML
<input type="search" id="searchBox" value="" onblur="dothis()" data-inline="true"    onKeyPress="blah();" />

I would like to capture the 'Done' key on the keyboard as well. I cant seem to find any information on this.

Thanks.

Upvotes: 2

Views: 2024

Answers (2)

Justin Noel
Justin Noel

Reputation: 6215

I've suggested using the blur event in my original answer. However, I think a better idea is simply to listen for the keyboard hiding - which will happen after the "Done" button is pressed.

window.addEventListener('keyboardDidHide', function () {
  // Describe your logic which will be run each time keyboard is closed.
});

https://github.com/cjpearson/cordova-plugin-keyboard#keyboarddidhide

Also, be sure the deregister this listener after you've done whatever you need to do after the keyboard hides. Otherwise, it will fire every time the keyboard hides in other parts of your app.

Upvotes: 2

Justin Noel
Justin Noel

Reputation: 6215

Unfortunately, pressing the "Done" key does not fire a keyCode event. So, I can't seem to find a way to detect it either.

I think the only option is to detect the "blur" event on your field. If the event occurs, then fire whatever action you need. Of course, this is only useful if you have a single field. If you have more than one field, using "blur" to be the equivalent of "Go" or "Submit" is useless.

Let us know if you found a better workaround.

Upvotes: 2

Related Questions