1. #1
    Sencha User
    Join Date
    Feb 2009
    Posts
    38
    Vote Rating
    0
    col is on a distinguished road

      0  

    Default Problems with add->remove->add component in Window

    Problems with add->remove->add component in Window


    There is such a decisive way the problem with the content of the form (with fields).
    here http://extjs.com/forum/showthread.ph...975#post323975
    In my case the problem relates to the content window.

    This example does not work as expected.
    PHP Code:
    var window = new Ext.Window( {
        
    width       300
        
    ,height     300
        
    ,layout     'fit'
        
    ,buttons:[{
          
    text 'Add Form'
          
    ,handler : function() {
            
    window.add(form);
            
    window.doLayout();
          }
        },{
          
    text 'Del Form'
          
    ,handler : function() {
            
    window.removeAll()
            
    window.doLayout();
          }
        }]

    } );

    var 
    form = new Ext.form.FormPanel( {
        
    labelWidth 150
        
    ,items:[{fieldLabel:'testLabel'xtype:'textfield'value:'testValue'}]
    });

    window.show(); 
    After little voodoo, something that worked.

    Code:
    var window = new Ext.Window( {
        width       : 350
        ,height     : 300
        ,layout     : 'fit'
        ,buttons:[{
          text : 'Add Form'
          ,handler : function() {
            window.add(form);
            window.doLayout();
          }
        },{
          text : 'Del Form'
          ,handler : function() {
            window.removeAll();
            window.doLayout();
            
            form.rendered=false;
            form.items.each(function(item){item.rendered=false});
            form.tools=false;
          }
        }]
    
    } );
    
    var form = new Ext.form.FormPanel( {
        labelWidth : 150
        ,items:[{fieldLabel:'testLabel', xtype:'textfield', value:'testValue'}]
    });
    
    window.show();
    Help me do this correctly.

  2. #2
    jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    Frederick MD, NYC, DC
    Posts
    16,360
    Vote Rating
    81
    jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all

      0  

    Default


    you *should not* and *can not* overwrite the window constant.

    That said:

    - removeAll destroy objects
    - No need to call doLayout on remove

    try this:
    Code:
    var buildForm = function() {
    
       return new Ext.form.FormPanel( {
        labelWidth : 150
        ,items:[{fieldLabel:'testLabel', xtype:'textfield', value:'testValue'}]
       });
    
    }
    
    var w = new Ext.Window( {
        width       : 300
        ,height     : 300
        ,layout     : 'fit'
        ,buttons:[{
          text : 'Add Form'
          ,handler : function() {
            w.add(buildForm());
            w.doLayout();
          }
        },{
          text : 'Del Form'
          ,handler : function() {
            w.removeAll();
            w.doLayout();
          }
        }]
    
    } );
    
    
    w.show();

  3. #3
    Sencha User
    Join Date
    Feb 2009
    Posts
    38
    Vote Rating
    0
    col is on a distinguished road

      0  

    Default


    WoW.... Big Tnx

    And how does it work?
    The examples differ only way to create a form variable.

  4. #4
    jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    Frederick MD, NYC, DC
    Posts
    16,360
    Vote Rating
    81
    jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all

      0  

    Default


    it works by recreating the form.

  5. #5
    Sencha User
    Join Date
    Mar 2009
    Posts
    356
    Vote Rating
    0
    koko2589 is on a distinguished road

      0  

    Default


    if removeall dont work add this its sloved it
    Code:
    Ext.override(Ext.Container, {
        removeAll: function(autoDestroy){
            this.initItems();
            var item, rem = [], items = [];
            this.items.each(function(i){
                rem.push(i)
            });
            for (var i = 0, len = rem.length; i < len; ++i){
                item = rem[i];
                this.remove(item, autoDestroy);
                if(item.ownerCt !== this){
                    items.push(item);
                }
            }
            return items;
        }
    });
    my ext js site
    http://www.itoto4.com/

  6. #6
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,502
    Vote Rating
    47
    Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    This very issue is being discussed in the Bugs folder right now.

  7. #7
    Sencha User
    Join Date
    Feb 2009
    Posts
    38
    Vote Rating
    0
    col is on a distinguished road

      0  

    Default


    To koko2589.
    fix, does not help

  8. #8
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,502
    Vote Rating
    47
    Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    Override the isValidParent method of the layout that you use to return false

  9. #9
    Sencha User
    Join Date
    Feb 2009
    Posts
    38
    Vote Rating
    0
    col is on a distinguished road

      0  

    Default


    Quote Originally Posted by Animal View Post
    Override the isValidParent method of the layout that you use to return false
    sample code pls

  10. #10
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,502
    Vote Rating
    47
    Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    pls