REQUIRED INFORMATION


Ext version tested:
  • Chrome 21
DOCTYPE tested against:
  • not important, this is a straight js error
Description:
  • Creating a record with a field {type:'date',allowNull:true,defaultValue:null} and no value creates an error in Ext.data.writer.Writer::writeDate, because date is null this line fails:
    return date.getTime()/1000;
Steps to reproduce the problem:
  • Create a record and save it with null as date value
The result that was expected:
  • saving of field value null
The result that occurs instead:
  • javascript error
Test Case:

Code:
Ext.define('MyApp.model.MyModel5', {
    extend: 'Ext.data.Model',
    config: {
        fields: ['id',{name:"nulldate",allowNull:true,defaultValue:null,type:"date"}],
        proxy: {
            type: 'direct', 
            api: {
                create: MyApp.myDirectStub.create
            },
            writer: {
                type: 'json',
                rootProperty: 'data'
            }
        }
    }
});
Ext.create('MyApp.model.MyModel5').save();




HELPFUL INFORMATION

Debugging already done:
  • yes
Possible fix:

Here is a fix everyone call use till Sencha fixed it:
Code:
 Ext.define('Ext.data.override.Writer', {
    override: 'Ext.data.Writer',
    writeDate: function (field, date) {
        if(date===null || !Ext.isDefined(date)) {
            if(field.getAllowNull()) {
                return null;
            } else {
                Ext.Error.raise('SOME ERROR MESSAGE HERE');
            }
        }
        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);
        }
    }
});
Best regards
Roland