    ContainerLayout
      AnchorLayout
        FormLayout

# Class Ext.layout.FormLayout

Package: | Ext.layout
Defined In: | FormLayout.js
Class: | FormLayout
Extends: | AnchorLayout

This layout manager is specifically designed for rendering and managing child Components of forms. It is responsible for rendering the labels of Fields.

This layout manager is used when a Container is configured with the `layout:'form'` layout config option, and should generally not need to be created directly via the new keyword. See `Ext.Container.layout` for additional details.

In an application, it will usually be preferrable to use a FormPanel (which is configured with FormLayout as its layout class by default) since it also provides built-in functionality for loading, validating and submitting the form.

A Container using the FormLayout layout manager (e.g. Ext.form.FormPanel or specifying `layout:'form'`) can also accept the following layout-specific config properties:

- `hideLabels`
- `labelAlign`
- `labelPad`
- `labelSeparator`
- `labelWidth`

Any Component (including Fields) managed by FormLayout accepts the following as a config option:

- `anchor`

Any Component managed by FormLayout may be rendered as a form field (with an associated label) by configuring it with a non-null `fieldLabel`. Components configured in this way may be configured with the following options which affect the way the FormLayout renders them:

- `clearCls`
- `fieldLabel`
- `hideLabel`
- `itemCls`
- `labelSeparator`
- `labelStyle`

Example usage:

    // 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({
        title: 'Form Layout',
        bodyStyle: 'padding:15px',
        width: 350,
        defaultType: 'textfield',
        defaults: {
            // applied to each contained item
            width: 230,
            msgTarget: 'side'
        },
        items: [{
                fieldLabel: 'First Name',
                name: 'first',
                allowBlank: false,
                labelSeparator: ':' // override labelSeparator layout config
            },{
                fieldLabel: 'Last Name',
                name: 'last'
            },{
                fieldLabel: 'Email',
                name: 'email',
                vtype:'email'
            }, {
                xtype: 'textarea',
                hideLabel: true,     // override hideLabels layout config
                name: 'msg',
                anchor: '100% -53'
            }
        ],
        buttons: [
            {text: 'Save'},
            {text: 'Cancel'}
        ],
        layoutConfig: {
            labelSeparator: '~' // superseded by assignment below
        },
        // config options applicable to container when layout='form':
        hideLabels: false,
        labelAlign: 'left',   // or 'right' or 'top'
        labelSeparator: '>>', // takes precedence over layoutConfig value
        labelWidth: 65,       // defaults to 100
        labelPad: 8           // defaults to 5, must specify labelWidth to be honored
    });

## Config Options

Config Options | Defined By
--- | ---
- | anchor : String This configuation option is to be applied to child items of a container managed by this layout (ie. configured with l... This configuation option is to be applied to child `items` of a container managed by this layout (ie. configured with `layout:'anchor'`). This value is what tells the layout how an item should be anchored to the container. `items` added to an AnchorLayout accept an anchoring-specific config property of anchor which is a string containing two values: the horizontal anchor value and the vertical anchor value (for example, '100% 50%'). The following types of anchor values are supported: Percentage : Any value between 1 and 100, expressed as a percentage. The first anchor is the percentage width that the item should take up within the container, and the second is the percentage height. For example:
      // two values specified
      anchor: '100% 50%' // render item complete width of the container and
                         // 1/2 height of the container
      // one value specified
      anchor: '100%'     // the width value; the height will default to auto
- Offsets : Any positive or negative integer value. This is a raw adjustment where the first anchor is the offset from the right edge of the container, and the second is the offset from the bottom edge. For example:
      // two values specified
      anchor: '-50 -100' // render item the complete width of the container
                         // minus 50 pixels and
                         // the complete height minus 100 pixels.
      // one value specified
      anchor: '-50'      // anchor value is assumed to be the right offset value
                         // bottom offset will default to 0
- Sides : Valid values are `'right'` (or `'r'`) and `'bottom'` (or `'b'`). Either the container must have a fixed size or an anchorSize config value defined at render time in order for these to have any effect. Mixed : Anchor values can also be mixed as needed. For example, to render the width offset from the container right edge by 50 pixels and 75% of the container's height use:
      anchor: '-50 75%'
| AnchorLayout
| defaultAnchor : String default anchor for all child container items applied if no anchor or specific width is set on the child item. Defaul... default anchor for all child container items applied if no anchor or specific width is set on the child item. Defaults to '100%'. | AnchorLayout
| extraCls : String An optional extra CSS class that will be added to the container. This can be useful for adding customized styles to t... An optional extra CSS class that will be added to the container. This can be useful for adding customized styles to the container or any of its children using standard CSS rules. See Ext.Component.ctCls also. Note: `extraCls` defaults to `''` except for the following classes which assign a value by default: Absolute Layout : `'x-abs-layout-item'` Box Layout : `'x-box-item'` Column Layout : `'x-column'` To configure the above Classes with an extra CSS class append to the default. For example, for ColumnLayout:
    extraCls: 'x-column custom-class'
| ContainerLayout
| fieldTpl : Ext.Template A compiled Ext.Template for rendering the fully wrapped, labeled and styled form Field. Defaults to:new Ext.Template(... A compiled Ext.Template for rendering the fully wrapped, labeled and styled form Field. Defaults to:
    new Ext.Template(
        '<div class="x-form-item {itemCls}" tabIndex="-1">',
            '<label for="{id}" style="{labelStyle}" class="x-form-item-label">{label}{labelSeparator}</label>',
            '<div class="x-form-element" id="x-form-el-{id}" style="{elementStyle}">',
            '</div><div class="{clearCls}"></div>',
        '</div>'
    );
This may be specified to produce a different DOM structure when rendering form Fields. A description of the properties within the template follows: `itemCls` : String The CSS class applied to the outermost div wrapper that contains this field label and field element (the default class is `'x-form-item'` and `itemCls` will be added to that). If supplied, `itemCls` at the field level will override the default `itemCls` supplied at the container level. `id` : String The id of the Field `labelStyle` : String A CSS style specification string to add to the field label for this field (defaults to `''` or the layout's value for `labelStyle`). `label` : String The text to display as the label for this field (defaults to `''`) `labelSeparator` : String The separator to display after the text of the label for this field (defaults to a colon `':'` or the layout's value for labelSeparator). To hide the separator use empty string ''. `elementStyle` : String The styles text for the input element's wrapper. `clearCls` : String The CSS class to apply to the special clearing div rendered directly after each form field wrapper (defaults to `'x-form-clear-left'`) Also see `getTemplateArgs` | FormLayout
| labelSeparator : String See Ext.form.FormPanel.labelSeparator. Configuration of this property at the container level takes precedence. | FormLayout
| renderHidden : Boolean True to hide each contained item on render (defaults to false). | ContainerLayout
| trackLabels : Boolean True to show/hide the field label when the field is hidden. Defaults to `true`. | FormLayout

## Public Properties

Property | Defined By
--- | ---
| fieldTpl : Ext.Template The Ext.Template used by Field rendering layout classes (such as Ext.layout.FormLayout) to create the DOM structure o... The Ext.Template used by Field rendering layout classes (such as Ext.layout.FormLayout) to create the DOM structure of a fully wrapped, labeled and styled form Field. A default Template is supplied, but this may be overriden to create custom field structures. The template processes values returned from Ext.layout.FormLayout.getTemplateArgs. | ContainerLayout
| if : Object This monitorResize flag will be renamed soon as to avoid confusion with the Container version which hooks onWindowRes... This monitorResize flag will be renamed soon as to avoid confusion with the Container version which hooks onWindowResize to doLayout monitorResize flag in this context attaches the resize event between a container and it's layout | ContainerLayout
| labelStyle : String Read only. The CSS style specification string added to field labels in this layout if not otherwise specified by each... Read only. The CSS style specification string added to field labels in this layout if not otherwise specified by each contained field. | FormLayout

## Public Methods

Method | Defined By
--- | ---
| getTemplateArgs( (Ext.form.Field field ) : Object Provides template arguments for rendering the fully wrapped, labeled and styled form Field. This method returns an ob... Provides template arguments for rendering the fully wrapped, labeled and styled form Field. This method returns an object hash containing properties used by the layout's fieldTpl to create a correctly wrapped, labeled and styled form Field. This may be overriden to create custom layouts. The properties which must be returned are: `itemCls` : String The CSS class applied to the outermost div wrapper that contains this field label and field element (the default class is `'x-form-item'` and `itemCls` will be added to that). If supplied, `itemCls` at the field level will override the default `itemCls` supplied at the container level. `id` : String The id of the Field `labelStyle` : String A CSS style specification string to add to the field label for this field (defaults to `''` or the layout's value for `labelStyle`). `label` : String The text to display as the label for this field (defaults to the field's configured fieldLabel property) `labelSeparator` : String The separator to display after the text of the label for this field (defaults to a colon `':'` or the layout's value for labelSeparator). To hide the separator use empty string ''. `elementStyle` : String The styles text for the input element's wrapper. `clearCls` : String The CSS class to apply to the special clearing div rendered directly after each form field wrapper (defaults to `'x-form-clear-left'`) Parameters: `field` : (Ext.form.Field The Field being rendered. Returns: `Object` An object hash containing the properties required to render the Field. | FormLayout
| parseMargins( Number|String v ) : Object Parses a number or string representing margin sizes into an object. Supports CSS-style margin declarations (e.g. 10, ... Parses a number or string representing margin sizes into an object. Supports CSS-style margin declarations (e.g. 10, "10", "10 10", "10 10 10" and "10 10 10 10" are all valid options and would return the same result) Parameters: `v` : Number|String The encoded margins Returns: `Object` An object with margin sizes for top, right, bottom and left | ContainerLayout

## Public Events

This class has no public events.