-
30 Aug 2012 9:54 PM #1
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
-
31 Aug 2012 6:39 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,599
- Vote Rating
- 434
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
________________
http://www.JSONPLint.com - Source to lint your JSONP!
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 almost in print!
When posting code, please use BBCode's CODE tags.
-
31 Aug 2012 10:06 AM #3
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 toon an item with "due_date" set to null, it blows up with the stack trace provided in the original post.Code:item.set('some_property'); store.sync();
-
31 Aug 2012 10:37 AM #4
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...)
A simple null check would prevent this...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); } },
Guess I'll just monkey patch with Ext.override until a fix is in...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); } },Last edited by subimage; 31 Aug 2012 at 10:47 AM. Reason: Figured out how to override in Ext
-
17 Nov 2012 5:05 AM #5
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.
Wait! Looks like we don't have enough information to add this to bug database. Please follow this template bug format.


Reply With Quote