mirror of
https://github.com/purplecabbage/phonegap-plugins.git
synced 2026-04-24 03:00:11 -04:00
-
Copy the .js file to your 'www' folder
-
Create a package com.phonegap.plugin
-
Copy the .java file into this package
-
Update your res/xml/plugins.xml file with the following line:
<plugin name="DatePickerPlugin" value="com.phonegap.plugin.DatePickerPlugin"/> -
Add a class="nativedatepicker" to your element for which you want the native datepicker
-
Add the following jQuery fragment to handle the click on these input elements:
$('.nativedatepicker').click(function(event) {
var currentField = $(this);
var myNewDate = Date.parse(currentField.val()) || new Date();
// Same handling for iPhone and Android
window.plugins.datePicker.show({
date : myNewDate,
mode : 'date', // date or time or blank for both
allowOldDates : true
}, function(returnDate) {
var newDate = new Date(returnDate);
currentField.val(newDate.toString("dd/MMM/yyyy"));
});
});
$('.nativetimepicker').click(function(event) {
var currentField = $(this);
var time = currentField.val();
var myNewTime = new Date();
myNewTime.setHours(time.substr(0, 2));
myNewTime.setMinutes(time.substr(3, 2));
// Same handling for iPhone and Android
plugins.datePicker.show({
date : myNewTime,
mode : 'time', // date or time or blank for both
allowOldDates : true
}, function(returnDate) {
var newDate = new Date(returnDate);
currentField.val(newDate.toString("HH:mm"));
});
});
- It is recommended to prefil these input fields and make these fields read only with a standard date format, preferably with three letter month so it can always be parsed.