-
4 Sep 2012 5:43 PM #1
Writer::writeDate bug for allowNull
Writer::writeDate bug for allowNull
REQUIRED INFORMATION
Ext version tested:- Chrome 21
- not important, this is a straight js error
- 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;
- Create a record and save it with null as date value
- saving of field value null
- javascript error
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
Here is a fix everyone call use till Sencha fixed it:
Best regardsCode: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); } } });
RolandRoland Schütz
Senior Software Architect
---
Bancha Project - Seamless integrate CakePHP with ExtJS and Sencha Touch
-
5 Sep 2012 5:12 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
Thanks for the report! I have opened a bug in our bug tracker.
-
12 Sep 2012 4:11 PM #3
A small change to the proposed workaround...
A small change to the proposed workaround...
Thanks for the workaround. I found that one line caused an issue for me, so I'd like to suggest an alteration:
field.dateFormat returns undefined, so dateFormat is always 'timestamp'.Code:var dateFormat = field.getDateFormat() || 'timestamp';
-
14 Nov 2012 1:09 AM #4
Thanks, this solved my problems with null dates.
Looking forward to having this added to Sencha Touch, so I can remove the override.
You found a bug! We've classified it as
TOUCH-3395
.
We encourage you to continue the discussion and to find an acceptable workaround while we work on a permanent fix.


Reply With Quote