Skip to content

Instantly share code, notes, and snippets.

@joshualambert
Forked from bilalq/datepicker.js
Created July 3, 2012 21:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshualambert/3043069 to your computer and use it in GitHub Desktop.
Save joshualambert/3043069 to your computer and use it in GitHub Desktop.
Date Picker in Titanium
var dateOfBirth = Ti.UI.createPicker({
type: Ti.UI.PICKER_TYPE_DATE,
minDate:new Date(1900,1,1),
maxDate:new Date(2000,1,1),
value:new Date(1995,8,1)
});
var birthDayLine = Ti.UI.createView({
layout: 'horizontal',
height: Ti.UI.SIZE,
top: 0,
left: '10%'
});
self.add(birthDayLine);
var dateLabel = Ti.UI.createLabel({
text: 'Birthdate: ',
font: {fontSize: 24},
color: '#fff',
});
birthDayLine.add(dateLabel);
var dateUpdated = false;
var dateValue = Ti.UI.createLabel({
text: 'Click here to select',
color: '#aaaafe',
left: 20
});
birthDayLine.add(dateValue);
dateValue.addEventListener('click', function(e) {
dateOfBirth.showDatePickerDialog({
value: new Date(1995,8,1),
callback: function(e) {
if (e.cancel) {
//Ti.API.info('User canceled dialog');
} else {
dateValue.value = e.value;
dateValue.text = (e.value.getMonth() + 1) + '/' + e.value.getDate() + '/' + e.value.getFullYear(),
dateUpdated = true;
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment