PDA

View Full Version : Load form on 'render' event but CompositeField not rendered yet.



jarlau
7 Apr 2010, 10:10 PM
I have a form with CompositeField(s).

I got an error "
f.items.each is not a function
return f.items.each(findMatchingField);
" when trying to do the following,



form.on('render', function() {
form.getForm().load({
url: 'xxx',
blah, blah, blah...
});
});


and I found it's because my CompositeField(s) are not rendered yet when setValues() trying to findField().

So I copied BasicForm.findField() to my overrides.js and changed as follows,


findField : function(id) {
var field = this.items.get(id);

if (!Ext.isObject(field)) {
//searches for the field corresponding to the given id. Used recursively for composite fields
var findMatchingField = function(f) {
if (f.isFormField) {
if (f.dataIndex == id || f.id == id || f.getName() == id) {
field = f;
return false;
} else if (f.isComposite && f.rendered === true) {
return f.items.each(findMatchingField);
}
}
};

this.items.each(findMatchingField);
}
return field || null;
},

it solves my problem.

But, is it a bug or any other solution?
Thanks in advanced.

jarlau
9 Apr 2010, 1:35 AM
friendly bump~

Animal
9 Apr 2010, 1:45 AM
This is why CompositeField should extend Container.

That way, any Fields which it contains will be pulled into the BasicForm's collection upon add.