Using the standard Panel title config to organize Ext JS form fields

May 14, 2008 by Jack Slocum

Yesterday while working on our internal support system I had a desire to organize the fields on a form a little better. I didn’t want to use a FieldSet and add full wrapping or another layer of indention in my form code (it’s indented deep enough!) so I decided to give the standard Panel title config attribute a try.

The Panels on my form were using baseCls:’x-plain’ which strips all styling except for required attributes for Ext layouts to function (e.g. overflow:hidden). As expected, the Panel titles looked pretty hideous with no styling. I came up with this simple, short solution and figured I would post it since others might find it useful. Although this application is running on an Ext JS 3.0 dev version, this code will work fine with Ext JS 2.x as well.

Getting started

First, I added some config options to the Panels:

{
    xtype:'panel',
 
    // add a title
    title:'Subscription Details',
 
    // make it collapsible 
    collapsible:true,
 
    // no animation, it looks odd (IMO)        
    animCollapse: false,
 
    // Clicking the title should trigger collapse/expand
    titleCollapse:true,
 
    // No collapse tool button needed
    hideCollapseTool: true,
 
    // generate markup with a custom prefix 'form-group' instead of x-panel or x-plain    
    baseCls:'form-group',
 
    ...

Hideousness

This technically worked, but wasn’t very aesthetically pleasing:

[image]

Add in some CSS…

So I added some CSS to my application’s CSS file:

/* add some padding so it spaces nice and relative elements dn't get clipped */
.form-group {
        padding-bottom:5px;
        overflow:hidden;
}
 
/* Simple blue border */
.form-group .form-group-header {
        padding:0;
        border-bottom:1px solid #c3daf9;
}
 
/* Position the text element so it appears over the border added above */
.form-group .form-group-header-text {
        font-size:11px;
        font-family:tahoma,arial,sans-serif;
        line-height:13px;
        text-transform:uppercase;
        position:relative;
        left:5px;
        top:5px;
        padding:1px 5px 1px 20px;
        color:#4e79b2;
        background:#fff url(../images/form-collapse-icon.gif) no-repeat 2px 0;
}
 
/* Copied from x-plain (for IE + layouts to work) */
.form-group-body {
    overflow:hidden;
}
 
/* Copied from x-plain (for IE + layouts to work) */
.form-group-bwrap {
    overflow:hidden;
    zoom:1;
}
 
/* Change the toggle icon when collapsed */
.x-panel-collapsed .form-group-header-text {
        background-position: 2px -15px;
}

Extellent!

I’m not a designer, but I was pretty happy with the result:

[image]

Reusable

I personally can’t handle setting all those config options on every form group I create and I really need the code I am working with to stay clean, so I created this simple extension:

Ext.ux.FormGroup = Ext.extend(Ext.Panel, {
        collapsible:true,
        animCollapse: false,
        titleCollapse:true,
        hideCollapseTool: true,
        baseCls:'form-group'
});
Ext.reg('formgroup', Ext.ux.FormGroup);

So now when I want to add a form group, it’s as simple as using a different xtype and setting a title:

{
    xtype:'formgroup',
    title:'Subscription Details',
    ...

Resources

The CSS sprite image used for the expand/collapse icon in the CSS above is available here.

25 Responses to “Using the standard Panel title config to organize Ext JS form fields”

Ryan

Looks great - what theme are you using there? Mind sharing it?

mdmadph

Well, that’s a neat way to create extensions on the fly for stored types like that.

You do realize that it’s gotten to the point where some of us have almost forgotten how to code regular javascript anymore, don’t you? :P

Nick D

Thanks for sharing Jack. Always interesting to see how you approach a problem. Your solution looks great! Is this application going to be available to subscription members?

Jack Slocum

@Ryan

It’s not an Ext theme, it’s just a look hacked up for this application.

@Nick

Once completed, it will be part of the subscriber area we are working on.

Jay Garcia

Pretty slick. It’s always nice to read how the ‘big boys’ do it :).

Jay Garcia

… One more thing. I think this demonstrates how, using the common patterns that you and company have demonstrated, can make life easy to create reusable components. I tell people time and time again - Ext can examined like leggos. the components can ’stack’ up on each other, to build complex components. An example of this is a ‘tabstrip toolbar’, which can be achieved in about 20 lines. Ext is just amazing stuff!

Daily del.icio.us for May 12th through May 16th — Vinny Carpenter’s blog

[…] Ext JS - Using the standard Panel title config to organize Ext JS form fields - Yesterday while working on our internal support system I had a desire to organize the fields on a form a little better. I didn’t want to use a FieldSet and add full wrapping or another layer of indention in my form code so I decided to give the standard […]

Adarsh Bhat

> I’m not a designer.

Who _is_ your designer? Must admit that s/he does an amazingly good job.

Angelo

Very very nice and clean “theme”.. and useful article…

..hope to see the theme shared.. ;-P

Jack Slocum

@Jay

I like that analogy. That’s exactly how I use it. A config option here, a subclass there and a new custom component for whatever I am working on is within reach.

@Adarsh Bhat

I’ll take that as a compliment. :)

mario

you understimate your design skills. i like your clean designs much more than those the designers i’ve had the displeasure to work with. to them usability is about photoshop ‘cheese’ effects. they throw in all the different gloss, gradient and bevel tricks even though you and i both know those effects are ridiculously easy to do in photoshop. you definitely raised the bar on how to create aesthetically pleasing widgets.

Biju Kunnappada

Thanks for the petty nice and simple hack Jack :)
Brillaint idea…

Cheers!,
Biju Kunnappada.
Nortel.

MikeB

Great looking Jack, and I like the little section on “Reusable” you put in (show’s a neat little trick for those of us still learning this toolset).

However I’m curious how this was an improvement instead of using fieldset’s? You’re still using a single panel for each section correct? Wouldn’t a fieldset have used the same “overhead” in terms of coding and layers and code indention?

Thanks
Mike B

Eric24

Very nice!

I’m new to ExtJS and just learning it. It would be very useful to me to see the code that creates the form (or maybe you could point me to some forum posts that would help me understand a) multi-column form field layouts and b) labels above the fields.

Thanks!
Eric

Steven Roussey

Jack:

“I’m not a designer, but I was pretty happy with the result”

OMG: Two reasons I chose that we should use ExtJS was that it was beautiful in code and in visual style. In fact, it was the visual style that stopped me long enough to bother looking at the code. Few people have a talent for both. And you do!

Steve

Thanks Jack. Looks good! We’ve been using the technique you mention in the Reusable section for a while, but I’m glad to see it “officially” documented so others can learn how much it helps…
I’m curious, is there a way to generally apply that technique, ie. imagine that I have a TextField, DateField, TextArea, custom field, etc. as part of a form and I want to apply a common set of config options to them with a one-line technique. Derivation is no longer possible; the ‘defaults’ config in the parent applies to more fields than we want. Is there some other way to pass in some override attributes I’m not thinking of? Could there be? :)

Nick

The look is fantastic, do you mind sharing the css file that you created ?

dajianshi

I’m not sure,Is not the fieldSet has the same behaviour

Carel

This kind of documentation is worth much more than the alternatives. most notably the api ref that does not provide working samples showing application of what is defined there. The forums give some help but we should have many many more of these blog entries.

drowsy

This is a great article, and I’d love to see more like it! Thank you for this.

oxyum

Sorry, but can you give me full JS (JSON) code of that form (only visual part)?

fastWebSearch

fastWebSearch

Big search engines can lead you in circles, in which case try a smaller targetted engine!

Anonymous

feed

add url car loan

add url car loan

After reading this post, I am not sure I understand what you are trying to relate. Please expand on your thoughts a little more. Thanks

ephedrine synthesis

ephedrine

ephedrine plus

Leave a Reply

To prove that you're not a bot, please answer this question:


© 2006-2008 Ext, LLC

Ext JS

Cross-browser JavaScript library for building rich internet applications


Ext GWT

Java library for building rich internet applications with GWT

Support Subscriptions

With 1-on-1 email and phone support, we solve your Ext JS, GWT, CSS and JavaScript issues


Training

Get up to speed quickly with on-site training provided by Ext


Community

The Ext community forums and wiki


Ext Solutions

Enterprise consulting and custom development

Ext JS


Ext GWT


Help


You are viewing a mobilized version of this site...
View original page here

Mobilized by Mowser Mowser