5
votes

I have tried to implement this Datetimepicker ( https://github.com/VitaliiBlagodir/cordova-plugin-datepicker ) but still not working on my Android Device ( Android 4.0.4).

  1. I added the plugin to my Project and used : cordova plugin add https://github.com/VitaliiBlagodir/cordova-plugin-datepicker.

  2. Put a Trigger to my js file and tried to test a alert("test"). I get the test alert on browser and on Device, but no alert from Datetimepicker?

  3. I also rm Android from Platform and build it again, everything is there, but still not working. ( To build the app, i am using PhoneGap Build)

  4. I have no idea what I am missing? .... any help would be nice :-).


Example:

in Html

<input type="text"  onclick="calendar()" />

in JS

<script>

function calendar(){

  alert("test")  //  is working

  var options = {
    date: new Date(),
    mode: 'date'
  };

  datePicker.show(options, function(date){
   alert("date result " + date);     // not working
  });

}

</script>

4
Also this is a native plugin so won't work on a browserSlartibartfast
It is working my android app. You should also add error method.Check your console log and post your error when calendar method get fired.Khurshid Ansari

4 Answers

2
votes

You don't have to add the script in your path.

Make sur you have register the plugin to your config.xml like so :

<feature name="DatePicker">
  <param name="ios-package" value="DatePicker"/>
</feature>

<feature name="DatePickerPlugin">
  <param name="android-package" value="com.okaybmd.cordova.plugin.datepicker.DatePickerPlugin"/>
</feature>

(more info @ http://phonegap-plugins.com/plugins/okaybmd/cordova-plugin-datepicker )

The plugin won't work in your browser. You have to test it through your device or an emulator.

0
votes

Did you include your script in your HTML ?

<script src="your/path/DatePicker.js"></script>
0
votes

The datepicker returns a promise, so you need to handle that on your code.

<script>

function calendar(){

  alert("test")  //  is working

  var options = {
    date: new Date(),
    mode: 'date'
  };

  datePicker.show(options).then(function(date){
   alert("date result " + date);
  });

}

</script>

Also, I have always used this with Angular, so not completely sure on how you inject the service for your usage.

Reference: http://ngcordova.com/docs/plugins/datePicker/

-1
votes

I used it for developing and Ionic app. The idea was to simply add the plugin (datepicker) and include ngCordova and ngCordovaMocks js files in your resources and the HTML.

ngCordovaMocks is for web development.

The injection was done while building apk or ipa at the main module

app.module('asas',['ngCordova'],function($cordovaDatePicker){

}).run()