Search code examples
extjsdynamicextjs3fieldset

ExtJS 3.4 : How to change fieldset size dynamically


I am trying to add an item into a fielset dynamically. I have checked the items of the fieldset in the console , the item is being added to the fieldset but it is not being displayed, I am invoking the doLayout() method for the fieldset and also for the formpanel which has this fieldset, but the size/height of the fieldset does not change. Can someone help me with this issue?

 if(csType.value=="OS"){
            Ext.apply(newOs,that.osCombo);
            newOs.id = 'testOs2';
            Ext.getCmp('cSFieldSet').add(newOs);
            Ext.getCmp('cSFieldSet').setHeight(600);
            Ext.getCmp('cSFieldSet').doLayout(true,true);
            Ext.getCmp('cSFieldSet').ownerCt.doLayout(true,true);
            that.csFormPanel.doLayout(true,true);
        }

I also tried using autoHeight: true, but still the item is not being displayed


Solution

  • Here's some test code I just wrote to simulate what you are trying to achieve:

    var simple = new Ext.FormPanel({
                labelWidth: 75, 
                frame:true,
                title: 'Simple Form',
                bodyStyle:'padding:5px 5px 0',
                width: 350,
                defaults: {width: 230},
                defaultType: 'textfield',
    
                items: [{
                    // Fieldset in Column 1
                    xtype:'fieldset',
                    itemId: 'fieldSetTest',
                    columnWidth: 0.5,
                    title: 'Fieldset 1',
                    collapsible: false,
                    autoHeight:false,
                    defaultType: 'textfield',
                    items :[{
                            fieldLabel: 'Field 1'
                        }, {
                            fieldLabel: 'Field 2'
                        }, {
                            fieldLabel: 'Field 3'
                        }
                    ]
                }
                ],
    
                buttons: [{
                    text: 'Add New Field',
                    handler: function() {
                        var newItem = new Ext.form.TextField({fieldLabel: 'New Fields'});
                        simple.getComponent('fieldSetTest').add(newItem);
                        simple.doLayout();
                    },
                    scope:this
                }]
            });
    
            simple.render(document.body);
    
        });
    

    This works fine, so on clicking the add button the new item appears in the fieldset and the height of the fieldset automatically increases. Without seeing your whole formpanel code I can't comment much further.