PDA

View Full Version : load form data into fields in nested container



bruijn88
16 Mar 2011, 5:10 AM
Hi all!

I'm having some troubles loading form data (populating fields) into fields which are located in a nested container in the form.

I went from this (http://dev.sencha.com/deploy/dev/examples/form/dynamic.js) example (form 5).
Code is as follows:


MyForm = Ext.extend(Ext.form.FormPanel, {

initComponent: function () {
var config;

config = {
url: 'save.php',
reader: new Ext.data.JsonReader({
idProperty: 'id',
fields: ['id', 'introduction', 'title', 'content']
}),
items: [{
xtype: 'textarea',
name: 'introduction'
}, {
xtype: 'tabpanel',
plain: true,
activeTab: 0,
deferredRender: false,
defaults: {layout: 'form'},
items: [{
title: 'Foo',
items: [{
xtype: 'textfield',
name: 'title'
}, {
xtype: 'textarea',
name: 'content'
}]
} /* more tabs */]
}]
};

Ext.apply(this, Ext.apply(this.initialConfig, config));
MyForm.superclass.initComponent.apply(this, arguments);

this.load({
url: 'data.php'
});
}

});


Example response:


{"id":1,"introduction":"Intro","title":"Foo","content":"Lipsum..."}


While i was digging i discovered that 'Ext.form.BasicForm.findField' only looks in it's own 'items' collection and doens't cascade/recurse into underlying containers. Therefore it only finds the 'introduction' field and populated that, but not the 'title' and 'content' fields.

Does anyone have an idea how to solve/work around this?

Thank in advance,
Zogs

johnathanhebert
16 Mar 2011, 7:27 AM
I copied your code exactly (and added a line to create a new MyForm() and render it) and it works for me... I see all 3 fields populated.

http://i52.tinypic.com/14ub67l.jpg

[EDIT]
I tested with ext-3.3.1

bruijn88
16 Mar 2011, 7:45 AM
johnathan,

thanks for your reply. In all honesty, i haven't tested the -exact- code i posted. It's a stripped version of what i'm really working with, but is essentially the same.
I'm surprised it works for you. Guess i need to run some more (isolated) tests..

Zogs

johnathanhebert
16 Mar 2011, 8:00 AM
What version of Ext are you using?

bruijn88
16 Mar 2011, 9:57 AM
Also 3.3.1

bruijn88
17 Mar 2011, 5:52 AM
johnathan,

Found it! Typo in reader config (fields did not match response). ><
I'll be in a corner crying if anyone needs me..

Zogs.