PDA

View Full Version : [DUP] [4.2] Models where a field is named 'length' causes issues



Vaevictus
6 Apr 2013, 9:16 AM
This just caught me out and have been pulling my hair out but got to the bottom of it.

If when you define a model, one of the fields is named 'length', Ext json readers happily parse json into the model properly.

Since the value of length I am returning from the remote server happens to be a large number, calling loadRecord of a formpanel with the record causes the browser to hang.

Workaround - don't use name : 'length' in your model :)

this is not really a bug per se, but I think Ext should at least warn you that your model has an illegal field name.

line 1450 ish in ext-all-debug.js:


toArray: function(iterable, start, end){
if (!iterable || !iterable.length) {
return [];
}


if (typeof iterable === 'string') {
iterable = iterable.split('');
}


if (supportsSliceOnNodeList) {
return slice.call(iterable, start || 0, end || iterable.length); <<<<hangs browser
}

slemmon
6 Apr 2013, 11:32 AM
I tried creating a test case to demonstrate the error, but I'm having trouble forcing an issue. Would you be able to create a simple test case.

My attempt


Ext.define('LengthModel', {
extend: 'Ext.data.Model',
fields:['name', 'email', 'length']
});


Ext.create('Ext.data.Store', {
storeId:'simpsonsStore',
//fields:['name', 'email', 'length'],
model: 'LengthModel',
data:{'items':[
{ 'name': 'Lisa', "email":"lisa@simpsons.com", "length":123456789012341234556 },
{ 'name': 'Bart', "email":"bart@simpsons.com", "length":5552221234 },
{ 'name': 'Homer', "email":"home@simpsons.com", "length":5552221244 },
{ 'name': 'Marge', "email":"marge@simpsons.com", "length":5552221254 }
]},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
});


Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [
{ text: 'Name', dataIndex: 'name' },
{ text: 'Email', dataIndex: 'email', flex: 1 },
{ text: 'Phone', dataIndex: 'length' }
],
height: 200,
width: 400,
renderTo: Ext.getBody()
});

Vaevictus
6 Apr 2013, 11:51 AM
run this in jsfiddle.net (couldnt save because I crashed the browser hehe).
This more accurately represents what my extjs app is doing



Ext.define('LengthModel', {
extend: 'Ext.data.Model',
fields: [{
name: 'name',
type: 'string'
}, {
name: 'email',
type: 'string'
}, {
name: 'length',
type: 'number'
}]
});




Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
//fields:['name', 'email', 'length'],
model: 'LengthModel',
// data: [],
proxy: {
type: 'memory',
reader: {
type: 'json',
// root: 'items'
}
}
});




var panel = Ext.create('Ext.form.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
items: [{
xtype: 'textfield',
fieldLabel: 'name'}],
height: 200,
width: 400,
renderTo: Ext.getBody()
});
var arr = [];
arr.push({
name : 'Lisa ',
email: "dfdfdflisa@simpsons.com",
length: "123456789012341227520"
});


panel.store.loadData(arr);
panel.loadRecord(panel.store.data.items[0]);




basically it's the formpanel.loadRecord() that doesnt like records where an item's name is length

slemmon
6 Apr 2013, 12:08 PM
Thank you very much for the report. I did another search and found that the issue is reported in the bug tracker.

Thanks for crashing my browser (Chrome at least - Firefox shrugged instead of crashing). :D

dieseldraft
8 Oct 2013, 8:38 AM
I have same issue but in Form. If my model has field with name "length" and i try use Form.setValues() i see just empty form. This happens because Ext.isIterable() check is object has property with name length.

Version: 4.2.0.663