views:

1398

answers:

3

I have an UIWebView that loads a HTML form.

When I select a text field the keyboard appears.

When I type and hit "Go" the form is submitted and the next page loads, but the keyboard does not go away, it stays on the screen.

The only way to get rid of the keyboard is to press the 'done' button on the keyboard or press the HTML submit button in the form.

Is it possible to make the keyboard disappear after hitting the Go button?

Thanks!

A: 

http://stackoverflow.com/questions/389825/dismiss-iphone-keyboard

[viewReceivingKeys resignFirstResponder]
Hafthor
A: 

The Go button equates to entering a return, and so you should take a look at the textFieldShouldReturn: method for a UITextFieldDelegate. Sample code (again taken from the link Hafthor posted):

- (BOOL)textFieldShouldReturn:(UITextField *)theTextField 
{
    NSLog(@"%@ textFieldShouldReturn", [self class]);
    [theTextField resignFirstResponder];
    // do stuff with the text
    NSLog(@"text = %@", [theTextField text]);
    return YES;
}
Tim
+2  A: 

You need to have the active input resign the focus as the form submits. The easiest way would be to call .blur() on all your inputs in your form's onsubmit event handler

<form onsubmit="document.getElementById('myInput').blur();">
    <input type="text" id="myInput"/>
</form>
rpetrich