I am loading an HTML page that has a form. I would like to be able to dismiss the keyboard when the user clicks on GO or if he clicks on the SUBMIT button on the HTML page.
If the user decides he doesn't want to fill out the form, I also need a way to dismiss the keyboard.
Not sure how to do this.
The javascript approach is clever, but this is more direct:
A more concise way without needing to know what element is selected is the following:
I'm not so familiar with UIWebView, but normally you would dismiss your keyboard like so...
By doing that, the keyboard would be dismissed...
To have the keyboard be dismissed when say the user clicks the return button, you would need to implement the delegate method.
Apple's documentation has a full list of methods for the UITextFieldDelegate.
UIGestureRecogniser will help to dismiss the keyboard when user clicks on the WebView. Here is the piece of code i used.
@objc func handleTap(_ sender: UITapGestureRecognizer) { webView?.endEditing(true) }
Hope the helps.
You can use javascript to take the focus away from the HTML text field using blur: