1. #1
    Sencha User
    Join Date
    Jan 2014
    Posts
    4
    Answers
    1
    Vote Rating
    0
    deggial is on a distinguished road

      0  

    Default Answered: Datefield format 'm/Y' error

    Answered: Datefield format 'm/Y' error


    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:
    Code:
    {
       xtype        : 'datefield',
       format        : 'm/Y',
       value        : ''
    },

    Thanks in advanced.

  2. 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:
    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:
    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.

  3. #2
    Touch Premium Member
    Join Date
    Jun 2011
    Posts
    1,084
    Answers
    112
    Vote Rating
    95
    Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light

      0  

    Default


    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).

  4. #3
    Sencha User
    Join Date
    Jan 2014
    Posts
    4
    Answers
    1
    Vote Rating
    0
    deggial is on a distinguished road

      0  

    Default


    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:
    before.png

    On focus lost:

    after.png

    Thanks in advanced.

  5. #4
    Touch Premium Member
    Join Date
    Jun 2011
    Posts
    1,084
    Answers
    112
    Vote Rating
    95
    Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light

      1  

    Default


    try this:

    Code:
    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?

  6. #5
    Sencha User
    Join Date
    Jan 2014
    Posts
    4
    Answers
    1
    Vote Rating
    0
    deggial is on a distinguished road

      0  

    Default


    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.

  7. #6
    Touch Premium Member
    Join Date
    Jun 2011
    Posts
    1,084
    Answers
    112
    Vote Rating
    95
    Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light Farish is a glorious beacon of light

      0  

    Default


    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).

  8. #7
    Sencha User
    Join Date
    Jan 2014
    Posts
    4
    Answers
    1
    Vote Rating
    0
    deggial is on a distinguished road

      0  

    Default


    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:
    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:
    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.
    Last edited by deggial; 3 Feb 2014 at 8:44 AM. Reason: Possible solution

Thread Participants: 1

Tags for this Thread