PDA

View Full Version : FormPanel items error



Dumas
19 Mar 2010, 7:10 AM
Hi!

I have a strange error which I don't understand at all (of course a bit simplified):

var items = [ [{name:'1'}], [{name:'2'}] ];
var formItems = {layout:'column', items: [
{ layout:'form', defaultType:'textfield', items: items[0] },
{ layout:'form', defaultType:'textfield', items: items[1] },
]};
That doesn't work at all (I get a "c is undefined" error), but when I change the fourth line to this it works:

{ layout:'form', defaultType:'textfield', items: Ext.decode(Ext.encode(items[1])) },

Any idea why this is?

thx
Dumas

Animal
19 Mar 2010, 7:30 AM
Why embed in arrays?



var items = [ {name:'1'}, {name:'2'} ];
var formItems = {layout:'column', items: [
{ layout:'form', defaultType:'textfield', items: items[0] },
{ layout:'form', defaultType:'textfield', items: items[1] },
]};

Dumas
19 Mar 2010, 11:14 AM
i thought that's the easiest way for converting grid columns (which weren't already initialized) to a two column form layout. Here's the full code:
http://www.extpaste.com/#3030

regards
Roland

Animal
19 Mar 2010, 3:23 PM
Take out [index]

BTW, are you stepping through this code in a debugger, or just reading it and trying to work out what it does?

Dumas
19 Mar 2010, 5:07 PM
Took me a while to see, you#re right. The problem was that I only defined every second array index. Thx. I've fixed it like this and now it works:



Ext.each(columns,function(val,index) {
// add the field name and the display name to the editor
val.editor.name = val.dataIndex;
val.editor.fieldLabel = val.header;
// push the new items to the itemlist
itemlist[pos].push(val.editor);
pos = pos ? 0 : 1; // change the column
});


I normally use the debugger with e.g. jquery, but with ExtJS I never had good experciences with going throught the code cause ext has so many nested functions, when you e.g. render a form there's I some hundred called functions, so that's just gets really confusing. At least to me, maybe I get better the more I understand what all the functions do....

Animal
19 Mar 2010, 11:11 PM
You MUST learn to step through Ext code. You are multiplying your debugging time by 10 if you just stare at code and try to work out what it's doing by dry running it in your head!

I'm all for reading and understanding code, but sometimes you have to see what it's actually doing!

Dumas
20 Mar 2010, 8:46 AM
Ok, I'll focus on that ;-)

Any tipps how to not get lost in the code or is it just experience?

thx
Dumas

Animal
20 Mar 2010, 8:52 AM
The code is just not that huge. Not the bits that run in response to any one event anyway.

Just use ext-all-debug.js and ext-base-debug.js, and you'll be able to solve any problem.

steffenk
20 Mar 2010, 9:08 AM
Just use ext-all-debug.js and ext-base-debug.js, and you'll be able to solve any problem.
but not the conceptional ones :)

Dumas
20 Mar 2010, 11:43 AM
I once stepped throught the whole window.hide() and for me it was quiete huge when you are in the 10th sub-function I get a bit confused...

Ok, but I'll try and learn it ;-)