Results 1 to 2 of 2

Thread: [ST 2.1.0-rc2] Sencha tries to apply date formatting for NULL date

    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
    Apr 2012
    Posts
    14
    Vote Rating
    2
      0  

    Default [ST 2.1.0-rc2] Sencha tries to apply date formatting for NULL date

    Proxy writer tries to apply date formatting for the model field with type "date" even if value of this field = null.


    Here is how model field declared:
    Code:
    {
        name: 'dateCompleted',
        type: 'date',
        dateFormat: 'Y-m-d',
        allowNull: true
    }
    Here is how it is handled in Writer.js:
    Code:
       writeDate: function(field, date) {
            var dateFormat = field.getDateFormat() || 'timestamp';
            switch (dateFormat) {
                case 'timestamp':
                    return date.getTime()/1000;
                case 'time':
                    return date.getTime();
                default:
                    return Ext.Date.format(date, dateFormat);
            }
        },
    
    
        /**
         * Formats the data for each record before sending it to the server. This
         * method should be overridden to format the data in a way that differs from the default.
         * @param {Object} record The record that we are writing to the server.
         * @return {Object} An object literal of name/value keys to be written to the server.
         * By default this method returns the data property on the record.
         */
        getRecordData: function(record) {
            var isPhantom = record.phantom === true,
                writeAll = this.getWriteAllFields() || isPhantom,
                nameProperty = this.getNameProperty(),
                fields = record.getFields(),
                data = {},
                changes, name, field, key, value;
    
    
            if (writeAll) {
                fields.each(function(field) {
                    if (field.getPersist()) {
                        name = field.config[nameProperty] || field.getName();
                        value = record.get(field.getName());
                        if (field.getType().type == 'date') {
                            value = this.writeDate(field, value);
                        }
                        data[name] = value;
                    }
                }, this);
            } else {
                // Only write the changes
                changes = record.getChanges();
                for (key in changes) {
                    if (changes.hasOwnProperty(key)) {
                        field = fields.get(key);
                        if (field.getPersist()) {
                            name = field.config[nameProperty] || field.getName();
                            value = changes[key];
                            if (field.getType().type == 'date') {
                                value = this.writeDate(field, value);
                            }
                            data[name] = value;
                        }
                    }
                }
                if (!isPhantom) {
                    // always include the id for non phantoms
                    data[record.getIdProperty()] = record.getId();
                }
            }
            return data;
        }
    Here is how it SHOULD BE handled not to cause fatal error:
    Code:
      writeDate: function(field, date) {
            var dateFormat = field.getDateFormat() || 'timestamp';
            switch (dateFormat) {
                case 'timestamp':
                    return date.getTime()/1000;
                case 'time':
                    return date.getTime();
                default:
                    return Ext.Date.format(date, dateFormat);
            }
        },
    
    
        /**
         * Formats the data for each record before sending it to the server. This
         * method should be overridden to format the data in a way that differs from the default.
         * @param {Object} record The record that we are writing to the server.
         * @return {Object} An object literal of name/value keys to be written to the server.
         * By default this method returns the data property on the record.
         */
        getRecordData: function(record) {
            var isPhantom = record.phantom === true,
                writeAll = this.getWriteAllFields() || isPhantom,
                nameProperty = this.getNameProperty(),
                fields = record.getFields(),
                data = {},
                changes, name, field, key, value;
    
    
            if (writeAll) {
                fields.each(function(field) {
                    if (field.getPersist()) {
                        name = field.config[nameProperty] || field.getName();
                        value = record.get(field.getName());
                        if (field.getType().type == 'date' && value !== null) {
                            value = this.writeDate(field, value);
                        }
                        data[name] = value;
                    }
                }, this);
            } else {
                // Only write the changes
                changes = record.getChanges();
                for (key in changes) {
                    if (changes.hasOwnProperty(key)) {
                        field = fields.get(key);
                        if (field.getPersist()) {
                            name = field.config[nameProperty] || field.getName();
                            value = changes[key];
                            if (field.getType().type == 'date') {
                                value = this.writeDate(field, value);
                            }
                            data[name] = value;
                        }
                    }
                }
                if (!isPhantom) {
                    // always include the id for non phantoms
                    data[record.getIdProperty()] = record.getId();
                }
            }
            return data;
        }

  2. #2
    Sencha User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,062
    Vote Rating
    1391
      0  

    Default

    Think this has already been fixed. Maybe a test case?
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •