Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mobile Safari Keyboard Form Submission

I have a basic form with a search input and a submit button within. When focus takes place in the input, the keyboard is displayed as expected. When I press the button, the form submit event occurs, in which I call event.preventDefault() and instead make an ajax call. However, when I press the search button on the keyboard, the keyboard just hides and no submit event occurs.

Why doesn't the form submit when I press search on the keyboard? How can I trigger this event to happen via the keyboard search button?

Thanks.

like image 376
Trevor Avatar asked Jun 22 '12 17:06

Trevor


1 Answers

The keyboard search button must be bound to a keypress event and has the keycode of 13.

Basically, listen to keypress events and return all calls except for e.which === 13

$('input').on('keypress', function ( e ) {
    if ( e.which !== 13 ) {
        return;
    }

    // ajax code
}
like image 159
Trevor Avatar answered Sep 22 '22 23:09

Trevor