Wait! Looks like we don't have enough information to add this to bug database. Please follow this template bug format.
  1. #1
    Sencha User
    Join Date
    Sep 2011
    Posts
    118
    Vote Rating
    5
    subimage is on a distinguished road

      0  

    Default Error when attempting to write/sync a record with a null date value

    Error when attempting to write/sync a record with a null date value


    REQUIRED INFORMATION




    Ext version tested:
    • Sencha 2.0.1.1


    Browser versions tested against:

    OS X Chrome (latest)
    Safari IOS


    DOCTYPE tested against:
    HTML 5


    Description:

    This is a bit involved, but it seems that Writer.js doesn't know how to deal with null values for dates when dealing with my proxy.

    If I try to sync a record that has a particular value for a date (which is optional on my back-end), the code works fine. However, when trying to sync a record that does not have a date in this field, the error occurs.


    Steps to reproduce the problem:

    * Read some records from JSON with dates...some dates should be filled, some null
    * Write a record with a null date


    Test Case:

    Here's my model definition...if I get back a 'null' value for 'due_date', then try to write that record again is where the bug happens.


    Code:
    Ext.define('CbMobile.model.LineItem', {
      extend: 'Ext.data.Model',
      labelCodes: [
        'neutral',
        'blue',
        'green',
        'yellow',
        'orange',
        'red'
      ],
      config: {
        fields: [
          {name:'id', type:'int'},
          {name:'comments_count', type:'int'},
          {name:'created_on', type:'date', dateFormat:'c'},
          {name:'description', type:'string'},
          {name:'due_date', type:'date', dateFormat:'c'},
          {name:'estimate_id', type:'int'},
          {name:'flat_fee', type:'float'},
          {name:'invoice_line_items_count', type:'int'},
          {name:'is_complete', type:'boolean'},
          {name:'is_taxable', type:'boolean'},
          {name:'label_code', type:'int'},
          {name:'markup_percentage', type:'float'},
          {name:'person_id', type:'int'},
          {name:'price_actual', type:'float'},
          {name:'price_per', type:'float'},
          {name:'project_id', type:'int'},
          {name:'project_list_id', type:'int'},
          {name:'quantity_low', type:'float'},
          {name:'quantity_high', type:'float'},
          {name:'rank', type:'int'},
          {name:'time_entry_minutes', type:'int'},
          {name:'title', type:'string'},
          {name:'type_code', type:'int'},
          {name:'unit_label', type:'string'},
          {name:'updated_at', type:'date', dateFormat:'c'}
        ],
        validations: []
      }
      labelColor: function() {
        return this.labelCodes[this.get('label_code')];
      },
      isComplete: function() {
        return (this.get('is_complete') == true);
      },
      toggleCompletion: function() {
        this.set('is_complete', !this.isComplete());
      }
    });



    HELPFUL INFORMATION


    I've attached a screenshot of the error trace from the Chrome javascript console.

    Screen shot 2012-08-30 at 10.45.49 PM.png

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,754
    Vote Rating
    828
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    I don't see a proxy or writer or anything here. Do you use a store? Can I get code that I can run locally?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Sep 2011
    Posts
    118
    Vote Rating
    5
    subimage is on a distinguished road

      0  

    Default


    Yo Mitchell,

    Like I said, it's pretty involved, and not sure you'll be able to get code that runs locally, but I've created a gist with all the moving parts, and some sample data here:

    https://gist.github.com/421e4f0f0d18305bfde2

    You'd need an account/login to access the API anyhow.

    Let me know if that helps.

    Basically, writing works for any records that have "due_date" set in the response from the server, but if I attempt to
    Code:
    item.set('some_property'); store.sync();
    on an item with "due_date" set to null, it blows up with the stack trace provided in the original post.

  4. #4
    Sencha User
    Join Date
    Sep 2011
    Posts
    118
    Vote Rating
    5
    subimage is on a distinguished road

      0  

    Default


    Really, I don't even think you need my code, as the error is happening here, assuming that "date" isn't being passed a null value.

    (Writer.js line 87...)

    Code:
        writeDate: function(field, date) {
            var dateFormat = field.dateFormat || 'timestamp';
            switch (dateFormat) {
                case 'timestamp':
                    return date.getTime()/1000;
                case 'time':
                    return date.getTime();
                default:
                    return Ext.Date.format(date, dateFormat);
            }
        },
    A simple null check would prevent this...

    Code:
        writeDate: function(field, date) {
            if(!date) return null;
            var dateFormat = field.dateFormat || 'timestamp';
            switch (dateFormat) {
                case 'timestamp':
                    return date.getTime()/1000;
                case 'time':
                    return date.getTime();
                default:
                    return Ext.Date.format(date, dateFormat);
            }
        },
    Guess I'll just monkey patch with Ext.override until a fix is in...
    Last edited by subimage; 31 Aug 2012 at 10:47 AM. Reason: Figured out how to override in Ext

  5. #5
    Ext Premium User
    Join Date
    Mar 2007
    Posts
    89
    Vote Rating
    1
    Luc is on a distinguished road

      0  

    Default


    Confirmed. I have the same issue. A field of type 'date' and e.g. a dataFormat: 'c' should be able to have a null value. writeDate should return null in this case.

Thread Participants: 2

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi