sectore / phonegap3-ios-datepicker-plugin

:x: [Deprecated] Migration of DatePicker iOS plugin to work with Cordova/PhoneGap 3
Other
26 stars 18 forks source link

Datepicker only show once #17

Closed hunchang closed 10 years ago

hunchang commented 10 years ago

hi, I'm using phonegap 3.0 and tested on iOS 7 device. I followed your guide to install the plugin using Cordova CLI, I'm not sure if I not calling the plugin correctly, the date picker only show once.

Either click done or cancel on the datepicker, if I click on the button again, it will not show the date picker for 2nd time and so on.

Below is my code

html

Show Date Picker

js var datepicker_options = { mode: 'datetime', date: new Date(), allowOldDates: false, allowFutureDates: true, doneButtonLabel: "Done", doneButtonColor: "#0000FF", cancelButtonLabel: "Cancel", cancelButtonColor: "#000000", x: "0", y: "0" };

$('#datePicker_show').tap(function() { console.log('clicked'); datePicker.show(datepicker_options, function(date){ console.log("date result " + date); }); });

sectore commented 10 years ago

Have you used the ios7 or master branch? Please note, that the master branch does not support iOS7 (only previous iOS7 beta, but it is deprecated now). To support iOS7 please use the ios7 branch.

hunchang commented 10 years ago

i'm using the ios7 branch, I installed the plugin based on your documentation. When the button is clicked, the datepicker only show once. The second time or the rest of the click on the button doesn't populate the datepicker. If you notice the button code on the above, I can trace "clicked" but the datepicker is not showing

sectore commented 10 years ago

Your JS code looks fine. One thing only, but I'm not sure: Your x and y values of datepicker_options have to be numbers, not strings.

What about the tap function, is it called every time? Any errors using the iPhone Simulator and the console of Safari?

hunchang commented 10 years ago

i'm using zepto instead of jquery. I have a button with an id called "datePicker_show", and "tap" is equal to "click" .

The only error I have in the iphone simulator is issue #11 My console show "clicked" which means the button is working properly, but the datepicker is not showing for the 2nd time.

sectore commented 10 years ago

Could you use latest version of PhoneGap (3.1.0 or better 3.2 instead of 3.0), please? After updating PhoneGap you have to update your project as described here: PhoneGap Doc -> Upgrading iOS

hunchang commented 10 years ago

ok, let me try that and update at here again

hunchang commented 10 years ago

no luck, upgraded to 3.2, but still can't show for the 2nd time. I did a list of tracking in DatePicker.js

Please see the below DatePicker.prototype.show = function(options, cb) {

var padDate = function(date) {
  //tracking here
  console.log(date + 'paddate');
  if (date.length == 1) {
    return ("0" + date);
  }
  return date;
};
var formatDate = function(date){
  date = date.getFullYear() 
        + "-" 
        + padDate(date.getMonth()+1) 
        + "-" 
        + padDate(date.getDate()) 
        + "T" 
        + padDate(date.getHours()) 
        + ":" 
        + padDate(date.getMinutes()) 
        + ":00Z";
  //tracking here         
  console.log(date + 'formatdate');

  return date
}

.....

on the 2nd click, padDate function is not showing any track back value.

hunchang commented 10 years ago

update: I changed the trace as below

var padDate = function(date) { console.log(date + 'paddate'); if (date.length == 1) { return ("0" + date); } return date; }; var formatDate = function(date){ console.log(date + 'first date'); date = date.getFullYear()

  return date
}

On the first click, the log shown the below result of the date "Wed Dec 04 2013 14:43:18 GMT+0800 (MYT)first date"

While on the 2nd click, the date became "2013-12-4T14:43:00Zfirst date"

I did a quick fix here by overriding the date again, options.date = new Date();

sectore commented 10 years ago

Your issues seems to be fixed with #18. This fix is checked in into master and ios7 branch. Please let me know if this update does solve your problem, too.