Results 1 to 6 of 6

Thread: Proper way to remove form items from a fieldset dynamically?

  1. #1

    Default Proper way to remove form items from a fieldset dynamically?

    This is related to my post:

    http://www.sencha.com/forum/showthre...901#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:

    Code:
    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):

    Code:
    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?

  2. #2
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890

    Default

    fieldSet.removeAll()

    Will remove and destroy all children.

  3. #3
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,245

    Default

    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?

  4. #4

    Default

    Quote Originally Posted by Animal View Post
    fieldSet.removeAll()

    Will remove and destroy all children.
    Thanks Animal, this did the trick.

  5. #5
    Sencha User
    Join Date
    Apr 2010
    Location
    Italy
    Posts
    17

    Default

    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?

  6. #6
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,245

Similar Threads

  1. FormPanel Dynamically Add/Remove Items after rendered
    By bhadresh4u in forum Ext 2.x: Help & Discussion
    Replies: 10
    Last Post: 8 May 2015, 4:32 AM
  2. dynamically add/remove/show/hide items from toolbar
    By aj3423 in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 27 Mar 2010, 4:30 AM
  3. form.items.each(remove): remove form fields
    By DPP in forum Ext 2.x: Help & Discussion
    Replies: 3
    Last Post: 7 Jan 2008, 1:15 AM
  4. add/remove panel items dynamically
    By fernando.florez in forum Ext 2.x: Help & Discussion
    Replies: 8
    Last Post: 19 Nov 2007, 10:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •