So im using the datepicker with ngCordova. The first time i call the datepicker everything works fine but when i call it a second time I receive the error:
Error: undefined is not a function (evaluating 'date.getFullYear()')
Yes. The fault is that you’ve used the example from the docs, which is not working.
Try the following on your browser’s command line:
console.log(typeof new Date(), typeof (new Date() - 1000));
for me this returns:
object number
That means; by subtracting 1000 from an object - you “killed it” by changing it’s type to number. Just try your code after removing the subtraction and the number. It surely will work. But now you will face the problem that you can’t choose another date than today, since the Date object always instantiates on the current date by default.
To be honest, the native handling of dates is pretty weird in JavaScript, so I decided to solve this problem by additionally using moment.js. Here is my options object:
First thank you for working on this with me. Unfortunately Im still receiving the same error. Everything works great the first time. Try to bring up datepicker again and same error.
Im using Ionic 1.0.0-beta.14 and ngCordova 0.1.11-alpha in the iOS Simulator.
But the solution isn’t perfect. I can’t yet explain why this is happening (I guess some sort of weird referencing issue) - but it works, if you move the definition of the options variable into the showDatePicker function.
I’ve found that the Android part of this plugin expects to receive an integer, while the iOS one expects to receive a Date object. So to make them both work you’ll need something like this:
minDate = ionic.Platform.isIOS() ? new Date() : (new Date()).valueOf();
datePickerOptions = {
date: new Date(),
minDate: minDate,
mode: 'date'
};
please solve this issue @tmuecksch cordova plugin add https://github.com/VitaliiBlagodir/cordova-plugin-datepicker i used this plugin in my sample app
i am getting date and time picker when first time set the date and time not showing in view if again click the text box it shows previous date and time in view when user click the text box this method will be called $scope.calendarData = function() {
alert(“hi”);
var options = {
date: new Date(),
mode: 'date'
};
datePicker.show(options, function(date) {
var monthName = "";
switch (date.getMonth()) {
case 1:
monthName = "Jan";
break;
case 2:
monthName = "Feb";
break;
case 3:
monthName = "Mar";
break;
case 4:
monthName = "Apr";
break;
case 5:
monthName = "May";
break;
case 6:
monthName = "Jun";
break;
case 7:
monthName = "Jul";
break;
case 8:
monthName = "Aug";
break;
case 9:
monthName = "Sept";
break;
case 10:
monthName = "Oct";
break;
case 11:
monthName = "Nov";
break;
case 12:
monthName = "Dec";
break;
}
var day = "";
switch (date.getDay()) {
case 0:
day = "Sun";
break;
case 1:
day = "Mon";
break;
case 2:
day = "Tue";
break;
case 3:
day = "Wed";
break;
case 4:
day = "Thu";
break;
case 5:
day = "Fri";
break;
case 6:
day = "Sat";
break;
}
$scope.calendar.register = day + ", " + date.getDate() + " " + monthName + " " + date.getFullYear();
alert($scope.calendar.startTime);
var options1 = {
date: new Date(),
mode: 'time'
};
datePicker.show(options1, function(date) {
var format;
var hours;
if (date.getHours() < 12) {
hours = date.getHours();
format = "AM";
} else {
hours = date.getHours() - 12;
format = "PM";
}
$scope.register += " " + hours + ":" + date.getMinutes() + " " + format;
});
});
};
i binded date and time value to ng-model: $scope.register here first i am getting time, before getting the time i have to select the datepicker. In this situation Can i use call back functions here.How
to write call back functions in ionic
I found out today that the date attribute was the troubling matter, at least in my case. What I did was just update date attribute every time the function that shows the datepicker triggers.
Could you tell why my calendar is showing with the wrong date?
If you see October 6 is today (Thursday - the Q letter), but it is showing as today (Thursday) was October 7.
The language used is Portuguese from Braszil by the way.