View Full Version : Datepicker value NaN only on phones?!?!?

15 Sep 2011, 11:51 PM
I am new in Touch, and I am going to create an application that must show a form in which there is an xtype datepickerfield.
The problem is that my code is OK only in Google Chrome but when I try it in a phone (Android or IOS) in the form datepickerfield appear NaN/NaN/NaN.

My code set the field with data from a store.

this is the field...

xtype: 'datepickerfield',
name: 'data',
label: 'Data',
id: 'iddataM',
required: true,
picker: { yearFrom: 2011, yearTo: 2100 }

and here when I set the field....

//gestione formattazione data
var dt = new Date(r_ddata);
var giorno = dt.format('d');
var mese = dt.format('m');
var anno = dt.format('Y');

//setto i dati presi dal db
Ext.getCmp("iddataM").setValue({year:anno, day:giorno, month:mese},true);

In Chrome ok...in phones not!!!:-?

Someone could have a solutions or some info about this???

Thanks a lot!

16 Sep 2011, 12:33 AM

first you have to set:

if(Ext.util.Format) { Ext.util.Format.defaultDateFormat = 'm/d/Y'; //or dynamically load it base to window.language

then where you want to add the data picker field:

xtype : 'datepickerfield',
picker : {
yearFrom : 2000,
yearTo : 2015
value:new Date(),

so if you want to set picker with your db value do this:

var parsedDate=Date.parseDate(DBDateString,'M$');//'M$' is the microsoft ajax date format, you use your db format
var millisecondVal=parsedDate.getTime();
var dateValue = new Date(millisecondVal);

Hope that this could help you.


16 Sep 2011, 1:29 AM
Hi Zux_ !
I have try some of your code but it doen't go...

I don't mind of millisecond and other values..I only use day,month and year and i take it from records on the db where every record have a field DDATA.
this field is passed via JSON in a store and showed on a List.
After I want to modify it and I want to set it in the datepickerfield but when I do this it is set only in Chrome but not on the phones showing only a NaN........

Maybe its a problem of formatting because in the db the date is in format 'Y-m-d' and in the datepickerfield I see is in 'm/d/Y' ( also if when I see the animation is in 'F/j/Y').

So if it is a problem of formatting what I have to set to format it?
Or maybe it is other things..?!?

Thanks for the idea and for your attempt!:)

Still thinking...:-?

16 Sep 2011, 2:45 AM
So if Chrome shows the date picker value correctly, then maybe implies that you parse and convert properly the date value from DB value to Sencha date picker format.
Probably, the problems with the other devices are that there have been set with other date formats in settings/international. Then you can try to use the first part of my shared code:

if(Ext.util.Format) {
Ext.util.Format.defaultDateFormat = 'm/d/Y';

And replace the 'm/d/Y' string with the related Sencha date format according to device set language (retrievable by window.language). In my example m/d/Y when language is en-us.


16 Sep 2011, 5:08 AM
Hey Zux_ now is Solved!!!:)

The problem was sure my misunderstanding of class Date in Touch.
Infact using in the right way the Date.parseDate() method now my date is display correctly also in phone devices like Android and IOS.

this is the right code :

//gestione parsing data in formato stringa/date
dt = Date.parseDate(r_ddata, "Y-m-d");

//setto i dati presi dal db

Now it's OK!!!=D>

Ps - hey sei italiano? anche io,di Milano!Grazie mille dell'aiuto,se potro un giorno restituiro!!!Grazie;)

16 Sep 2011, 6:06 AM
Perfect, problem fixed!

P.S. si sono di Treviso :), figurati di niente!

hehehe grazie! ;)