Closed mjstelly closed 10 years ago
Hi there and apologies for the late response. I hope I can help you out with your two issues.
The error message you receive when canceling the date entry is caused because the user didn't actually select a date. Here's an example of the full object returned when a user cancels:
{"cancel":true,"type":"date-picker","id":"birthdate","data":null}
As opposed to the full object when a user selects a date:
{"type":"date-picker","data":{"date":"1900-08-28T05:00:00.000Z","age":113,"unixMilliseconds":-2188321200000,"unixSeconds":-2188321200},"cancel":false,"id":"birthdate"}
You can see that the value of the "data" property is null. If you are treating null as an object and try to access a property that doesn't exist, you get the error message you're seeing. You should check for the "cancel" property in the result object to see if the user canceled or not.
I was successfully replicating this, and there was a mistake in my documentation and my own code. The problem is that Titanium ignores the property when maxDate is less than minDate. In the example I gave in the documentation, I am using this snippet:
var today = new Date();
var minDate = new Date(today.setYear(1900));
var maxDate = new Date(today.setYear(today.getYear()-18));
The problem here is that I'm using the same "today" date variable for both minDate and maxDate, which is a logic error. The correct code should look like this:
// Set minimum date to 1900.
var minDate = new Date(new Date().setYear(1900));
// Set minimum date to today - 18 years.
var maxDate = new Date(new Date().setYear(new Date().getYear()-18));
After I made this adjustment in the code, the widget worked correct.
Daniel, Great job on the widget. Works beautifully except for the
cancel
button and theminDate
assignment. Very possible I'm doing something wrong.First, the cancel button: When selecting it, I get an error.
(
e.data.date
is defined in theonDone
callback) At first, I thought this occurred when I simply opened and closed the picker without selecting a value. Not true. The error occurred regardless.Next is the
minDate
variable. I use moment.js to calculate the valuewhich returns the correct value
I have minDate defined in
pickerParams
:However, the user is able to select a date older than the minimum. I am expecting
minDate
to disallow selections older than this date, which is the converse ofmaxDate
where the user cannot select any date forward of 'maxDate`.I would appreciate your assistance on how to resolve these issues. Thanks.