PDA

View Full Version : [DUPE-949] CompositeField and Form.find



KimSchneider
7 Jul 2010, 10:23 PM
Hi,

I don't know if this is a bug or just my fault.

If I put a textfield into a compositefield and run form.find on the name of the textfield, I get no results. The Api says "Find a component under this container at any level by property"...

Example:



var form = new Ext.form.FormPanel({
items : [{
xtype : 'compositefield',
items : [{
xtype : 'textfield',
name: 'city',
flex : 1
}]
}]
});

form.find('name', 'city');


This returns an empty array...Any solution for this?

tobiu
8 Jul 2010, 9:08 AM
try out:


form.getForm().findField('city');



kind regards,
tobiu

Jamie Avins
8 Jul 2010, 11:24 AM
Related To:
http://www.extjs.com/forum/showthread.php?98554-Loading-data-into-a-composite-field-s-children-on-FormPanel-render
http://www.extjs.com/forum/showthread.php?100503-DUPE-949-Fields-inside-CompositeFields-are-missing-in-BasicForm.items

Stju
8 Jul 2010, 3:27 PM
Try this override:


//Override for finding fields in composite, checkboxgroups or radiogroups
Ext.override(Ext.BasicForm, {
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) {
return f.items.each(findMatchingField);
} else if (f.isRadioGroup && f.rendered) {
return f.items.each(findMatchingField);
} else if (f.isCheckboxGroup && f.rendered) {
return f.items.each(findMatchingField);
}
}
};
this.items.each(findMatchingField);
}
return field || null;
}
});

KimSchneider
8 Jul 2010, 9:26 PM
Thanks for your replies.

As I dont like overrides, will work with



form.getForm().findField('city');


:)

Stju
8 Jul 2010, 9:40 PM
@Kim Schneider

Sure, You can patch original code without override ;)
As bugreport 949 states there is problem with composite fields, so form.getForm().findField('city') in your case won't work.
The same applies when You want to load data in form with composite fields and radio/checkbox groups. They won't be loaded without this patch (as of version 3.2.2) as original version of findField look only on first level and don't go deeper ;)

KimSchneider
8 Jul 2010, 9:52 PM
Hm, strange...I'm using



form.getForm().loadRecord


and



form.getForm().findField


AFTER the form is rendered and displayed to the user and both works perfect with composite fields.