/* * Ext JS Library 2.3.0 * Copyright(c) 2006-2009, Ext JS, LLC. * licensing@extjs.com * * http://extjs.com/license */ /** * @class Ext.layout.FormLayout * @extends Ext.layout.AnchorLayout *
This layout manager is specifically designed for rendering and managing child Components of forms. * It is responsible for rendering the labels of {@link Ext.form.Field Field}s.
*This layout manager is used when a Container is configured with the layout:'form' {@link Ext.Container#layout layout} config, * and should generally not need to be created directly via the new keyword. In an application, * it will usually be preferrable to use a {@link Ext.form.FormPanel FormPanel} (which automatically uses FormLayout as its layout * class) since it also provides built-in functionality for loading, validating and submitting the form.
*Note that when creating a layout via config, the layout-specific config properties must be passed in via * the {@link Ext.Container#layoutConfig layoutConfig} object which will then be applied internally to the layout.
*The {@link Ext.Container Container} using the FormLayout can also accept the following layout-specific config * properties: *
Any type of components can be added to a FormLayout, but items that inherit from {@link Ext.form.Field} * can also supply the following field-specific config properties: *
// Required if showing validation messages
Ext.QuickTips.init();
// While you can create a basic Panel with layout:'form', practically
// you should usually use a FormPanel to also get its form functionality
// since it already creates a FormLayout internally.
var form = new Ext.form.FormPanel({
labelWidth: 75,
title: 'Form Layout',
bodyStyle:'padding:15px',
width: 350,
labelPad: 10,
defaultType: 'textfield',
defaults: {
// applied to each contained item
width: 230,
msgTarget: 'side'
},
layoutConfig: {
// layout-specific configs go here
labelSeparator: ''
},
items: [{
fieldLabel: 'First Name',
name: 'first',
allowBlank: false
},{
fieldLabel: 'Last Name',
name: 'last'
},{
fieldLabel: 'Company',
name: 'company'
},{
fieldLabel: 'Email',
name: 'email',
vtype:'email'
}
],
buttons: [{
text: 'Save'
},{
text: 'Cancel'
}]
});
*/
Ext.layout.FormLayout = Ext.extend(Ext.layout.AnchorLayout, {
/**
* @cfg {String} labelSeparator
* The standard separator to display after the text of each form label (defaults to a colon ':'). To turn off
* separators for all fields in this layout by default specify empty string '' (if the labelSeparator value is
* explicitly set at the field level, those will still be displayed).
*/
labelSeparator : ':',
// private
getAnchorViewSize : function(ct, target){
return (ct.body||ct.el).getStyleSize();
},
// private
setContainer : function(ct){
Ext.layout.FormLayout.superclass.setContainer.call(this, ct);
if(ct.labelAlign){
ct.addClass('x-form-label-'+ct.labelAlign);
}
if(ct.hideLabels){
this.labelStyle = "display:none";
this.elementStyle = "padding-left:0;";
this.labelAdjust = 0;
}else{
this.labelSeparator = ct.labelSeparator || this.labelSeparator;
ct.labelWidth = ct.labelWidth || 100;
if(typeof ct.labelWidth == 'number'){
var pad = (typeof ct.labelPad == 'number' ? ct.labelPad : 5);
this.labelAdjust = ct.labelWidth+pad;
this.labelStyle = "width:"+ct.labelWidth+"px;";
this.elementStyle = "padding-left:"+(ct.labelWidth+pad)+'px';
}
if(ct.labelAlign == 'top'){
this.labelStyle = "width:auto;";
this.labelAdjust = 0;
this.elementStyle = "padding-left:0;";
}
}
if(!this.fieldTpl){
// the default field template used by all form layouts
var t = new Ext.Template(
'