Results 1 to 4 of 4

Thread: [2.1][INFO REQ] Form Field onDestroy() called twice

  1. #1

    Default [2.1][INFO REQ] Form Field onDestroy() called twice

    Form Field onDestroy() method is called twice. Here is a test case

    Code:
    var TestField = function(conf) {
      TestField.superclass.constructor.call(this, conf);
    }
    
    Ext.extend(TestField, Ext.form.TextField, {
      onDestroy : function() {
        console.info("Destroying Test Field ....");
        TestField.superclass.onDestroy.call(this);
      }});

    Code:
    new Ext.Window({
               autoHeight: true,
               width: 560,
               items:new Ext.form.FormPanel({items:[new TestField({})]})}).show();
    It breaks our application because we use custom fields (TreePanel) which fails on second onDestroy() call. See http://extjs.com/forum/showthread.ph...7&goto=newpost

    In addition to fixing double onDestroy() call in form fields you might consider defensive check on childNodes != null in TreeNode destructor

    Thanks,
    Alex

  2. #2
    Sencha User
    Join Date
    Apr 2012
    Location
    Austin, Texas
    Posts
    4

    Default

    I don't think this is really a bug. True, in this case, both the base Container and the BasicForm attempt to destroy their items which, for form fields, can be the same items. However, if you look at the code for Ext.destroy(), if you attempt to destroy something that doesn't exist (already destroyed) it will simply skip the logic. If the item is still a valid reference, then attempting to remove listeners and remove the DOM element should not hurt anything. The test case you gave demonstrates that the method is called twice, but it runs fine with no error. Are you sure there's not something in your custom field code that's causing your error?

    TreeNode.childNodes will always exist (it's defined in the base class Ext.data.Node as this.childNodes = []; ). There is other code in TreeNode that assumes childNodes to be non-null, so I don't think a null check is needed.

  3. #3

    Default

    Hi Brian,

    In TreeNOde code destroy() sets childNodes to null so second invocation of destroy() causes error:

    Code:
    destroy: function () {
        for (var i = 0, l = this.childNodes.length; i < l; i++) {
            this.childNodes[i].destroy();
        }
        this.childNodes = null;
        if (this.ui.destroy) {
            this.ui.destroy();
        }
    }

  4. #4

    Default

    Hi,

    i would like to restart this topic, because i face the same error. I have a basic setup: Window -> FormPanel -> TabPanel -> TreePanel (on first tab). When i close the window, i get an error: this.childNodes has no properties (in ext-all-debug.js line 23122). So this is basically the same issue. I checked it and TreeNode.destroy method is beeing called twice. The first time it's run fine (destroying all nodes), but the second time it's beeing called (on the root node) this.childNodes is null (like roytmana mentioned), so this "for" loop fails.

    Setting this.childNodes to "[]" instead of "null" on line 23125 helped to solve this issue. Are there any plans for this before the next release?

    Cheers,
    Michael

    Update: using 2.1

Posting Permissions

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