PDA

View Full Version : Datefield format 'm/Y' error



deggial
31 Jan 2014, 4:47 AM
Hello,

when I choose a month with less than 31 days and my system current date is 31 chosen month goes to next (today is Jan 31, if I select Feb 2014 datefield changes to March 2014).

My code:

{
xtype : 'datefield',
format : 'm/Y',
value : ''
},



Thanks in advanced.

Farish
31 Jan 2014, 5:24 AM
I am not sure if I understand your problem. I tried it and it seems to work fine. However, since the format doesnt contain the day, this information is not stored and no matter which day of the month you choose, when you reopen the datefield picker, the last day of the that month is selected (even if you had choosen some other day).

deggial
31 Jan 2014, 5:38 AM
Hi Farish,


when I choose Feb, first show the correct format, however when datefield lost the focus automatically changes date to March. Look at the following screenshots


With focus:
47757

On focus lost:

47756

Thanks in advanced.

Farish
31 Jan 2014, 5:48 AM
try this:


Ext.create('Ext.form.Panel', {
renderTo: Ext.getBody(),
width: 300,
bodyPadding: 10,
title: 'Dates',
items:
[
{
xtype: 'datefield',
anchor: '100%',
fieldLabel: 'From',
format: 'm/Y',
name: 'from_date',
value: ''
},
{
xtype: 'datefield',
anchor: '100%',
fieldLabel: 'To',
name: 'to_date',
value: new Date() // defaults to today
}
]
});

are you doing something else with the date's rendering/calculation?

deggial
3 Feb 2014, 1:47 AM
Hi Farish,

I've tried your code and doesn't work and I'm doing nothing with the date.

Today, Feb 3, works fine, however if I change the current system date to Jan 31 fails again (change Feb, 2014 to Mar, 2014 on focus lost).

I read in other forum that Ext JS get the current day when format a date without day, so that if day is 31 and February has 28 goes to next month, March.

I'm still looking for a solution.

Thanks.

Farish
3 Feb 2014, 1:49 AM
thats strange. i tried it on the day you posted it which was 31st Jan but i didnt see this problem. which version of ExtJS are you using? may be it was a bug in earlier version? I tried it with the code editor within the documentation (using 4.2.2).

deggial
3 Feb 2014, 4:04 AM
Hi Farish,

I'm using ExtJS 4.1.

Edit:
I've changed createParser function from ../ext-4/ext-debug.js file and now works fine. I 've added this line "dt.setDate(1);" after a "new Date" sentence to force the day of the date to be the first day of the month.

Original Code:

createParser : (function() {
var code = [
"var dt, y, m, d, h, i, s, ms, o, z, zz, u, v,",
"def = Ext.Date.defaults,",
"results = String(input).match(Ext.Date.parseRegexes[{0}]);",

"if(results){",
"{1}",

"if(u != null){",
"v = new Date(u * 1000);",
"}else{",
"dt = Ext.Date.clearTime(new Date);",
"y = Ext.Number.from(y, Ext.Number.from(def.y, dt.getFullYear()));",
"m = Ext.Number.from(m, Ext.Number.from(def.m - 1, dt.getMonth()));",
"d = Ext.Number.from(d, Ext.Number.from(def.d, dt.getDate()));",
.
.
.
}

Modified Code:

createParser : (function() {
var code = [
"var dt, y, m, d, h, i, s, ms, o, z, zz, u, v,",
"def = Ext.Date.defaults,",
"results = String(input).match(Ext.Date.parseRegexes[{0}]);",

"if(results){",
"{1}",

"if(u != null){",
"v = new Date(u * 1000);",
"}else{",
"dt = Ext.Date.clearTime(new Date);",
"dt.setDate(1);",

"y = Ext.Number.from(y, Ext.Number.from(def.y, dt.getFullYear()));",
"m = Ext.Number.from(m, Ext.Number.from(def.m - 1, dt.getMonth()));",
"d = Ext.Number.from(d, Ext.Number.from(def.d, dt.getDate()));",
.
.
.
}

However I don't know if this change affects other code. I've tried with datefields formated with and without day and in both cases works fine.


Thanks.