Trouble with PhoneGap Contact service. If a field is missing or blank, the code stops.
OK, I have been having trouble with this for a few weeks and am really frustrated...
I have an app setup with the PhoneGap contacts service to import a contact's information (based on a filter [displayname]).
When invoked by a button click, the service returns the contact ($) into a grid.
Inside that grid, I have several other grids... One for the phone numbers, one for the email addresses, and one for the addresses. In each of the grids, there is a text box where the values are displayed.
Using echo in the web preview or compiling in xcode and loading onto an actual device this all works great.
I need to take all of the values for each returned section and put them into one visible text box (the grids mentioned earlier will be hidden). For example... I want each email address in all of the email address grid text boxes to be added together into one visible text box (like "a href="mailto:email1@mail.com" rel="nofollow"email1@mail.com/a, a href="mailto:email2@mail.com" rel="nofollow"email2@mail.com/a, a href="mailto:email3@mail.com" rel="nofollow"email3@mail.com/a"..)
I have been able to get this to work by adding the following javascript to the Email_Input box inside the email grid...
code
var emails, newEmails = '';
emails = Appery('EmailVisible_Input').val();
newEmails = '';
if (value != undefined){
if (phones != ''){
var regex = new RegExp( '\b' + value + '\b' ); //check to see if it is a duplicate entry
if (regex.test(emails) == false){
newEmails = (emails + ", " + value); //at least one addresses already returned, add to the end
} else {
newEmails = emails; //this is the first address returned
}
} else {
newEmails = (type + ": " + value);
}
Appery('EmailVisible_Input').val(newEmails);
}
/code
This works great when there is at least one email address returned by the service.
The problem I have is if no email address is returned (either controlled by modifying the echo response or by importing a contact (that doesn't have an email address) on a phone with a compiled version.
When this happens in the browser preview, the page stops and all further loading halts.
When this happens on an actual phone (xcode compiled and echo turned off), the page freezes and the loading animation keeps spinning indefinitely.
It seems that what ever I try to test for the presence of a value, it freezes if there is not value.