I am trying to create a contact form using the PhoneGap API accompanied with javascript and HTML5 for the form layout. By contact form I mean I want to be able to add new contacts and search for existing ones. So far I followed a tutorial/video off the Adobe Website to do this.
A few Notes: * I have to use PhoneGap 1.9.0 * It has to run on Android 2.3.3 Level 10 * I am not an overly confident programmer
The code I have is:
JS
$( document ).bind( 'deviceready', function() {
$('#btnCreate').bind('touchstart', function() {
var contact = navigator.contacts.create();
var name = null;
contact.displayName =
$( 'txtFirst' ).attr('value') + ' ' + $( 'txtLast' ).attr('value');
contact.nickname =
$( 'txtFirst' ).attr('value') + ' ' + $( 'txtLast' ).attr('value');
name = new ContactName();
name.givenName = $( 'txtFirst' ).attr('value');
name.familyName = $( 'txtFirst' ).attr('value');
contact.name = name;
contact.emails = [
new ContactField ( 'home', $( '#txtEmail' ).attr('value'), true )];
contact.phoneNumbers = [
new ContactField ( 'mobile', $( '#txtMobile' ).attr('value'), true )];
contact.save(function() {
$('#txtFirst').attr('value', '');
$('#txtLast').attr('value', '');
$('#txtEmail').attr('value', '');
$('#txtMobile').attr('value', '');
}, function() {
console.log( 'Error' );
} );
} );
$( '#btnFind' ).bind( 'touchstart', function() {
var fields = ['*'];
var options = {
filter: $( '#txtLast' ).attr( 'value' ), multiple:true };
navigator.contacts.find( fields, function(contacts) {
$( '#txtFirst').attr('value', contacts[0].name.givenName );
$( '#txtLast').attr('value', contacts[0].name.familyName );
$( '#txtEmail').attr('value', contacts[0].emails[0].value );
$( '#txtMobile').attr('value', contacts[0].phoneNumber[0].value );
}, function(error) {
console.log('Error');
},
options );
});
});
HTML5
<div data-role="content">
<div id="contactContainer" >
<form id="lblFirst" > First Name: </form>
<input id="txtFirst" placeholder="First Name"/>
<form id="lblLast"> Last Name: </form>
<input id="txtLast" placeholder="Last Name"/>
<form id="lblEmail"> Email: </form>
<input id="txtEmail" placeholder="Email"/>
<form id="lblMobile"> Phone : </form>
<input id="txtMobile" placeholder="Phone"/>
<button id="btnCreate" data-corners="false">Create Contact </button>
<button id="btnFind" data-corners="false"> Find Contact </button>
</div>
</div>
Thanks for your time
You have to use the Contact plugin in Phonegap/Cordova. maybe this video tutorial could help you out as it shows you how to use HTML5 and PhoneGap to create contacts on a user's mobile device..
您可能需要检查ContactPicker插件以使用本机ui创建和搜索联系人,您要做的就是自己添加文件并更新配置文件,而无需使用phonegap cli。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.