Embedding a FormPanel in another FormPanel

| | Comments (2)

Often I want to create a pre-configured class to encapsulate some form fields in a reusable way. When doing this, however, you cannot extent Ext.FormPanel - if you do this and then try to embed your class in an existing FormPanel you’ll get an obscure error deep in the bowels of ExtJS. :(

Instead, extend Ext.Panel, and then create a FormPanel inside your panel. For example, here’s a simple “LocationPanel” that displays a Campus and Building labels. Note that the class extends Ext.Panel, and then embeds a ‘form’ xtype, and the form fields are inside that…

    LocationPanel = Ext.extend(Ext.Panel, {
        campus: 'defaultCampus',
        building: 'defaultBuilding',

        width: 300,
        height: 50,
        frame: true,
        border: true,
        labelWidth: 75,
        title: 'Location Panel',

        initComponent: function(){
            Ext.apply(this, {
                items: [{
                layout: 'form',
                    items: [{
                        layout: 'column',
                        items: [{
                            columnWidth: '.5',
                            layout: 'form',
                            items: [{
                                    xtype: 'label',
                                    text: this.campus
                            }]
                        }, {
                            columnWidth: '.5',
                            layout: 'form',
                            items: [{
                                    xtype: 'label',
                                    text: this.building
                            }]
                        }]
                    }]
                }]
            });
            LocationPanel.superclass.initComponent.apply(this, arguments);
        }
    });
    Ext.reg('location_panel', LocationPanel);

2 Comments

I found your post because I am interested in creating a search form panel that can be reused in portlets. Being relatively new to Ext I am not sure from your example of where to start. Could you provide some insight. (i.e. can I put this in a separate js file?).

Thanks

The above example is a "pre-configured class" See http://extjs.com/learn/Tutorial:Writing_a_Big_Application_in_Ext and http://extjs.com/learn/Manual:Component:Extending_Ext_Components for a description of this pattern.

Leave a comment

About this Entry

This page contains a single entry by Bill Hutten published on July 13, 2008 9:43 PM.

Classes with custom events was the previous entry in this blog.

Creating a TreePanel from markup is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Categories

Pages

Powered by Movable Type 4.1