I'm working on an iOS app that uses HTML for a section -- the bulk of the app is native. I am using the shouldStartLoadWithRequest/custom url scheme mechanism described in great detail all over SO. It's been working great. The issue I've found, however, involves text/textarea fields. In a standalone browser environment, typing text in a text element and then tapping a checkbox (or radio) will fire the on change event for both the text element and the checkbox/radio button. However, I'm finding that in the UIWebView, I'm only getting the onchange when giving the checkbox/radio button focus.
I am trying to stay away from jQuery as much as possible due to the overhead in the UIWebView and the lack of a speedy JavaScript interpreter.
Thanks in advance for any assistance.
Here is my JavaScript:
var allTextFields = document.querySelectorAll("input[type=text]");
for (var i = 0; i < allTextFields.length; i++)
{
allTextFields[i].onchange = function(){
var scheme = document.getElementById('scheme').value;
value = this.value;
url = scheme + ':' + this.id + ':' + value;
window.location = url;
}
}
var allTextAreas = document.querySelectorAll("textarea");
for (var i = 0; i < allTextAreas.length; i++)
{
allTextAreas[i].onchange = function(){
value = this.value;
var scheme = document.getElementById('scheme').value;
url = scheme + ':' + this.id + ':' + value;
window.location = url;
}
}
var allSelects = document.querySelectorAll("select");
for (var i = 0; i < allSelects.length; i++)
{
allSelects[i].onchange = function(){
value = this.value;
var scheme = document.getElementById('scheme').value;
url = scheme + ':' + this.id + ':' + value;
window.location = url;
}
}
var allCheckboxFields = document.querySelectorAll("input[type=checkbox]");
for (var i = 0; i < allCheckboxFields.length; i++)
{
allCheckboxFields[i].onchange = function(){
value = this.value;
var scheme = document.getElementById('scheme').value;
url = scheme + ':' + this.id + ':'+ this.checked;
window.location = url;
}
}
and here is the Objective-C
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = [request URL];
if ([[url scheme] isEqualToString:@"file"])
{
return YES;
}
else
{
NSString *valueString = [url resourceSpecifier];
NSArray *values = [valueString componentsSeparatedByString:@":"];
[self updateDatabase:[url scheme] fieldName:values[0] value:values[1]];
}
return NO;
}