titanium-sdk icon indicating copy to clipboard operation
titanium-sdk copied to clipboard

feat(android): datepicker range

Open m1ga opened this issue 2 years ago • 3 comments

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.

Screenshot_20220407-230444

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

m1ga avatar Apr 07 '22 21:04 m1ga

In case it helps: This is how we're currently using the date range picker!

hansemannn avatar Apr 09 '22 14:04 hansemannn

Is datePickerRange: true when from AND to is set?

caspahouzer avatar Apr 12 '22 08:04 caspahouzer

Is datePickerRange: true when from AND to is set?

no, it doesn't work this way automatically. That will still create the normal datepicker and ignores those parameters.

m1ga avatar Apr 12 '22 08:04 m1ga