How do I set the value of a date picker?
I'm using the following to set the selected value of a date picker:
picker.value = win.selectedDate;
where selectedDate is a custom property on the Window.
But this doesn't seem to work. The date picker always defaults to the system date.
Am I doing something wrong or is this a bug?
6 Answers
-
It's already 2 years and it is still not possible to dynamically change value of date picker. It is sometimes quite annoying to develop in decelerator (uh eh sry I mean appcelerator).
-
The Kitchen Sink demo shows how to set the default value of the picker:
var value = new Date(); value.setFullYear(2009); value.setMonth(0); value.setDate(1); var picker = Ti.UI.createPicker({ type:Ti.UI.PICKER_TYPE_DATE, value:value });
-
the solution is simple, but I had to give a look to the source code to get it. the API documentation is poor.
this worked for me:
var default_date = new Date(2010, 05, 05); var picker_date = Titanium.UI.createPicker({ type: Titanium.UI.PICKER_TYPE_DATE, value: default_date });
you have to use the object Date of javascript, you can find a description here
pay attention to the month and the day fieds, because indexes starts from 0.
eg: Jun 04 2010 => new Date(2010, 05, 05);
-
I'm not sure if this helps, but I've found after initializing the picker view the only way to change the value of the picker is to have initialized a 'change' EventListener:
mPicker.addEventListener('change',function(e){});
After adding this listener I could update the value of the data picker with:
mPicker.value = <<some date>>;
-
You can find out the perfect month view here.
http://titaniumexplorers.blogspot.in/2012/09/titanium-calendar-month-view.html
-
Even faster, supposing you are working with Alloy and have a date picker with id="date_picker".
var value = new Date("2015-06-18"); $.date_picker.value = value;