Reputation: 388
I am using the Phonegap Datepicker plugin for Android.
I am not able to see the datepicker when I open the screen. I am getting this error.
09-13 22:37:55.894: E/Web Console(13123): Uncaught TypeError: Cannot call method 'show' of undefined at file:///android_asset/www/index.html:689
My code looks like:
<div data-role="controlgroup">
<p>
<label for="airportName">Airport</label> <input type="text" name="airportName" id="airportName" class="custom" />
<label for="selectDate">Date</label> <input type="text" name="selectDate" id="selectDate" class="nativedatepicker" />
</p>
and I have the used the event handler like
$('.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("yyyy-MM-dd"));
// This fixes the problem you mention at the bottom of this script with it not working a second/third time around, because it is in focus.
currentField.blur();
});
});
Is there any link where I can see an example of how this plug-in in used apart from the usual example shown in the documentation?
Upvotes: 2
Views: 4522
Reputation: 5139
The things you must do is to change DatePickerPlugin.java
because if not with the new Cordova 2.0
won't work.
After changing two lines in this file, calling from Javascript
won't trouble you again.
Change:
final DroidGap currentCtx = (DroidGap) ctx.getContext();
for this:
final Context currentCtx = cordova.getActivity();
Find this:
ctx.runOnUiThread(runnable);
and replace for:
cordova.getActivity().runOnUiThread(runnable);
Read this thread for further information: datePicker plugin not working in Phonegap 2.0
Upvotes: 5