Workaround for bug 1317 '"What's up" textarea on iPhone missing proper submit button'

http://laconi.ca/trac/ticket/1317

Mobile Safari shows a 'return' button for making newlines in a <textarea> where it would show a submit button for plain <input> text fields...
However there's a keydown event handler which is supposed to detect hitting enter and submit the form for us. This didn't work on Mobile Safari because it was checking of 13 ("\r") but the iPhone sends us char 10 ("\n") here. Changed to accept both, so we now submit on hitting 'return' on iPhone.

Note: I also added a blur() to move focus out of the textarea, which closes the on-screen keyboard. It will also take focus out of the textarea on other platforms, but this is probably the right thing -- the same thing happens when you push the "send" button after all.

Also note: unfortunately the layout right now looks pretty awful generally while editing on the iPhone; you can't see the send button or character counter while typing at the default zoom, and it doesn't zoom out after you submit so you can't really see where your message is going. This should be dealt with in general by fixing up the mobile skin variant...
This commit is contained in:
brion 2009-08-09 18:39:51 -07:00 committed by Craig Andrews
parent e9ed20a69d
commit a1a97930f3
1 changed files with 4 additions and 1 deletions

View File

@ -55,10 +55,13 @@ $(document).ready(function(){
}
function submitonreturn(event) {
if (event.keyCode == 13) {
if (event.keyCode == 13 || event.keyCode == 10) {
// iPhone sends \n not \r for 'return'
$("#form_notice").submit();
event.preventDefault();
event.stopPropagation();
$("#notice_data-text").blur();
$("body").focus();
return false;
}
return true;