-
9 Dec 2012 9:28 AM #1
Model: the order of 'convert' fields can be broken
Model: the order of 'convert' fields can be broken
REQUIRED INFORMATION
Ext version tested:- Sencha 2.1
- Chrome 23.0
- Sencha applies sorting to Model fields based on 'covert' function existence in order to ensure that fields with 'convert' are at the bottom.
But it seems that in some cases sorting can reorder equal items thus breaking initially configured order and dependencies between 'convert' fields.
It seems there is no need to apply sorting to fields array and enough to go through all fields once moving 'non-convert' fields to the top. This would keep the order of 'convert' fields.
- Create model as in the test case with 'convert' fields depending each other -> view fields array, the order of 'convert' fields is different to the configured order.
- Create a record of that model -> error appears because some of expected fields are not set yet.
Code:Ext.define('User', { extend: 'Ext.data.Model', config: { fields: [ { name: 'first_name', type: 'string' }, { name: 'first_name2', type: 'string' }, { name: 'first_name3', type: 'string' }, { name: 'first_name4', type: 'string' }, { name: 'first_name5', type: 'string' }, { name: 'first_name6', type: 'string' }, { name: 'last_name', type: 'string' }, { name: 'letters1', convert: function (v, record) { return record.get('last_name').substr(0, 2); } }, { name: 'letters2', convert: function (v, record) { return record.get('letters1').substr(0, 1); } }, { name: 'letters4', convert: function (v, record) { return record.get('letters1').substr(0, 1); } }, { name: 'letters5', convert: function (v, record) { return record.get('letters1').substr(0, 1); } }, { name: 'letters6', convert: function (v, record) { return record.get('letters1').substr(0, 1); } }, { name: 'letters7', convert: function (v, record) { return record.get('letters1').substr(0, 1); } } ] } }); User.getFields().keys // fields are reordered: id is added at position 1, first_name2 is moved to position 7, letters1 is moved to bottom position 13 so that letters2, letters3, etc can't be properly set now var user = Ext.create('User', { first_name: 'Ed', last_name: 'Spencer' }); // -> Error; Cannot call method 'substr' of undefined
-
10 Dec 2012 6:51 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,107
- Vote Rating
- 453
Thanks for the report! I have opened a bug in our bug tracker.
You found a bug! We've classified it as
TOUCH-3811
.
We encourage you to continue the discussion and to find an acceptable workaround while we work on a permanent fix.


Reply With Quote