PDA

View Full Version : Proper way to remove form items from a fieldset dynamically?



ClemsonJeeper
2 Sep 2010, 7:04 AM
This is related to my post:

http://www.sencha.com/forum/showthread.php?25479-2.0.1-2.1-Field.destroy()-on-Fields-rendered-by-FormLayout-does-not-clean-up.&p=505901#post505901

Basically, I have a ComboBox above FieldSet. In the ComboBox the user selects an option and then it dynamically changes the contents of the FieldSet depending on the choice.

The code I use to remove all the entries in the fieldset is:




var ra = Ext.getCmp('reportArguments');
ra.items.each(function(item) {
ra.items.remove(item);
Ext.destroy(item);
});



I then go in and add new components (items in the array of new components):



for (var i = 0; i < items.length; i++) {
ra.add(items[i]).show();
}
ra.show();
ra.doLayout();


This worked fine in 2.X with the override at the front of this post.

Since then, I've upgraded to 3.2.2 and added:

Ext.layout.FormLayout.prototype.trackLabels = true;

But now, it gets confused and starts adding labels where it shouldn't, as well as not even adding the components themselves (just the labels).

It's like Ext.destroy() actually isn't destroying the objects at all.

Any help with this? Am I going about this the wrong way?

Animal
2 Sep 2010, 7:08 AM
fieldSet.removeAll()

Will remove and destroy all children.

Condor
2 Sep 2010, 7:12 AM
It all depends on what items contains. It should only contain config objects, because any instantiated component would get destroyed when removed.

ps. Wouldn't it be easier to make the fieldset layout:'card' and only switch the card when a different item is selected in the combobox?

ClemsonJeeper
2 Sep 2010, 11:17 AM
fieldSet.removeAll()

Will remove and destroy all children.

Thanks Animal, this did the trick.

bariand
5 Nov 2010, 5:44 AM
I have the same issue with a fieldSet, but using fieldSet.removeAll() I obtain an uncaught exception when I try to re-populate the fieldSet:
uncaught exception: Element.alignToXY with an element that doesn't exist
Basically I need to re-build the fieldSet in a form every time a leaf node on a tree is selected.
I tried some tricks stated into various posts, but without success.
Any idea about this issue?

Condor
5 Nov 2010, 5:49 AM
Bug #989 (http://www.sencha.com/forum/showthread.php?99695-OPEN-989-alignToXY-error-when-dynamically-adding-removing-Numberfield-from-Panel).