How to refresh Date Picker

You must Login before you can answer or comment on any questions.

Hello,

I am trying to set a value to a Date Picker, when the picker window is opened.

This worked fine on custom picker using "setSelectedRow". But how does it work on a Date Picker ?

Is picker.value holding the Data ?

Here my attempt

// Refresh Date Picker
Ti.UI.currentWindow.addEventListener('open', function()
{
var new_date = Titanium.App.Properties.getString("start_date");
Ti.API.info(new_date);
}
info displays : 2010-08-29 09:14:38 +0200

How to make the date picker display the Date in "new_date" ?

Regards David

— asked 3 years ago by David P.
3 Comments
  • I too would like an answer to this. Seems that setting the date property of a DatePicker after it has been added to the parent does not refresh the control. Funny think is that the change to the date property is applied as a later query of the date property shows the updated value.

    Could this just be a UI refresh bug?

    — commented 3 years ago by Sean Clark

  • I would also like to set the date of a datepicker after it has already been created, but didn't find the solution yet.

    — commented 2 years ago by Tamas Rakoczi

  • I'm facing the same issue, anyone already got the solution? Sean, Tamas, Dimitri, have you all found the solution?

    — commented 11 months ago by Derek Chai

2 Answers

I'm using a modified forms.js helper

https://gist.github.com/2995709

then in my code I set value

function snapForm(btnAction, data, launcherWin) {
 
       var forms = require('/lib/ti/forms');
 
    if(btnAction != 'btnEdit')
    {
        //new snap
        var d1 = new Date();
        //var d2 = new Date().toISOString();
    }
    else
    {
        //edit snap
        var moment = require('/lib/thirdParty/moment.min');
        var da = moment(data.dateFor, "YYYY,MM,DD");
        var db = new Date(da);
        var d1 = new Date(da);
        //var d2 = data.dateFor;
    }
 
var fieldsCore = [
        { title:'Date For', type:'date', id:'dateFor', isHidden:true, value:d1  },
    ];
relevant bit from gist above
else if (type === exports.TYPE_DATE) {
        if (isAndroid) {
            fieldObject = Ti.UI.createPicker({
                type: Ti.UI.PICKER_TYPE_DATE,
                value:field.value
            });
 
            //fieldObject.type = type;
            fieldObject.id = id;
            handleStyle(form, fieldObject, title, isHidden, labelRefs);
        } else {
            fieldObject = Ti.UI.createTextField(textFieldDefaults);
            fieldObject.type = type;
            fieldObject.id = id;
            fieldObject.value = field.value;
            handleStyle(form, fieldObject, title, isHidden, labelRefs);
            setupPickerTextField(fieldObject, Ti.UI.PICKER_TYPE_DATE);
        }

Your Answer

Think you can help? Login to answer this question!