titanium-sdk
titanium-sdk copied to clipboard
feat(android): datepicker range
Adds datePickerRange: true
to the datepicker to allow to pick a date range. Since we are using the MaterialDatePicker it is very easy to add.
var win = Ti.UI.createWindow({});
var btn = Ti.UI.createButton({
title: "pick"
});
win.add(btn);
win.open();
btn.addEventListener("click", function() {
Ti.UI.backgroundColor = 'white';
var picker = Ti.UI.createPicker({
type: Ti.UI.PICKER_TYPE_DATE,
minDate: new Date(2022, 3, 1),
maxDate: new Date(2022, 11, 31),
from: new Date(2022, 3, 2),
to: new Date(2022, 3, 10),
datePickerRange: true,
title: "Pick a range..."
});
picker.showDatePickerDialog({
value: new Date(),
callback: function(e) {
if (e.cancel) {
Ti.API.info('User canceled dialog');
} else {
Ti.API.info('User selected date: ' + e.from + " - " + e.to);
}
}
});
});
It will use either value
or from
and to
for the selected range.
Todo:
- change the property
datePickerRange
name? - documentation
In case it helps: This is how we're currently using the date range picker!
Is datePickerRange: true
when from
AND to
is set?
Is
datePickerRange: true
whenfrom
ANDto
is set?
no, it doesn't work this way automatically. That will still create the normal datepicker and ignores those parameters.