3

I have a Cordova app running on iOS. I've implemented a search box with this html:

<form>
  <input type="search" class="historySearchTextbox" id="myFilter" placeholder="Search" spellcheck="false" autocorrect="off">
</form>

This works fine and gives me a 'Go' button instead of return on the popup keyboard. I can capture taps on the Go button with this javascript:

$('#myFilter').on('keyup', function (e) {
    var theEvent = e || window.event,
        keyPressed = theEvent.keyCode || theEvent.which;
    if (keyPressed === 13) {
        filter();
        document.activeElement.blur();
    }
    return true;
});

But I still have the 'done' button to deal with on the keyboard. I believe there is no keycode that I can use, and my own testing agrees. Based on reading answers on stack overflow, the best I can do is detect when the keyboard goes away. I'm using this javascript:

$("#myFilter").bind('blur', function (event) {
    window.alert("blur");
});

This works but I'd rather have a direct way of detecting a 'done' key tap.

Any suggestions?

Thanks!

Jon

Jon Schlossberg
  • 329
  • 2
  • 11

1 Answers1

-7

The done key is the same as the enter key. So you can listen to a keypress event. I'm writing this using jQuery and i use it in coffee script so I'm trying to convert it back to js in my head. Sorry if there is an error.

$('someElem').bind("keypress", function(e){
// enter key code is 13
if(e.which === 13){
    console.log("user pressed done");
} 
})
  • Hi, thanks your quick response. I just tried it though and this does not fire when I hit the 'done' button. Also, I should have mentioned that I want the Go button snd the done button to do different things. – Jon Schlossberg Mar 30 '16 at 15:42
  • This is definitely not true, this answer should be deleted – Nathan Apr 10 '18 at 07:46