1. #1
    Sencha User
    Join Date
    Jun 2012
    Posts
    82
    Answers
    7
    Vote Rating
    1
    dr-dan is on a distinguished road

      0  

    Default Answered: Is it necessary to encode dates for ajax posts to .net handlers?

    Answered: Is it necessary to encode dates for ajax posts to .net handlers?


    In essence i am having to override the save method of a model, because when using the proxy (via save()), dates are sent in the format MS enjoys when serializing into JSON. (i.e. ticks since 1970), due to me specifying the field as an MS date.

    But, when posting back, they decided they don't particularly like dates in this format, so the date doesn't get read into my view, it needs formatting first into y-m-d format.

    The only way round it, is to encode the json and do a bog standard ajax call (having overridden the encoding for dates in my app):

    Code:
    Ext.JSON.encodeDate = function (d) {
          return Ext.Date.format(d, '"Y-m-d"');
    };
    and

    Code:
    saveRecord: function () {
            var me = this;
            var data = me.getData(false);
            Ext.Ajax.request({
                scope: me,
                url: "/wex",
                method: "POST",
                jsonData: Ext.encode(data)
            });
        }
    Not ideal really...

  2. Do you mean that the date formats for the reading and updating will be different? In that case, you can use field serialize.
    Code:
    fields: [{
        name: 'fieldName',
        type: 'date',
        dateFormat: 'MS', // format for reading 
        serialize: function(value){
            return Ext.Date.format(value, 'Y-m-d');
        }
    },{
        ...
    }]

  3. #2
    Sencha - Community Support Team
    Join Date
    Jan 2012
    Posts
    1,376
    Answers
    346
    Vote Rating
    113
    vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all

      0  

    Default


    Do you mean that the date formats for the reading and updating will be different? In that case, you can use field serialize.
    Code:
    fields: [{
        name: 'fieldName',
        type: 'date',
        dateFormat: 'MS', // format for reading 
        serialize: function(value){
            return Ext.Date.format(value, 'Y-m-d');
        }
    },{
        ...
    }]

  4. #3
    Sencha User
    Join Date
    Jun 2012
    Posts
    82
    Answers
    7
    Vote Rating
    1
    dr-dan is on a distinguished road

      0  

    Default


    Ah just what I was looking for.

    Thanks

Thread Participants: 1