1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-form.FieldContainer-method-constructor'><span id='Ext-form.FieldContainer'>/**
2 </span></span> * @class Ext.form.FieldContainer
3 * @extends Ext.container.Container
5 FieldContainer is a derivation of {@link Ext.container.Container Container} that implements the
6 {@link Ext.form.Labelable Labelable} mixin. This allows it to be configured so that it is rendered with
7 a {@link #fieldLabel field label} and optional {@link #msgTarget error message} around its sub-items.
8 This is useful for arranging a group of fields or other components within a single item in a form, so
9 that it lines up nicely with other fields. A common use is for grouping a set of related fields under
10 a single label in a form.
12 The container's configured {@link #items} will be layed out within the field body area according to the
13 configured {@link #layout} type. The default layout is `'autocontainer'`.
15 Like regular fields, FieldContainer can inherit its decoration configuration from the
16 {@link Ext.form.Panel#fieldDefaults fieldDefaults} of an enclosing FormPanel. In addition,
17 FieldContainer itself can pass {@link #fieldDefaults} to any {@link Ext.form.Labelable fields}
18 it may itself contain.
20 If you are grouping a set of {@link Ext.form.field.Checkbox Checkbox} or {@link Ext.form.field.Radio Radio}
21 fields in a single labeled container, consider using a {@link Ext.form.CheckboxGroup}
22 or {@link Ext.form.RadioGroup} instead as they are specialized for handling those types.
23 {@img Ext.form.FieldContainer/Ext.form.FieldContainer1.png Ext.form.FieldContainer component}
26 Ext.create('Ext.form.Panel', {
27 title: 'FieldContainer Example',
32 xtype: 'fieldcontainer',
33 fieldLabel: 'Last Three Jobs',
36 // The body area will contain three text fields, arranged
37 // horizontally, separated by draggable splitters.
54 renderTo: Ext.getBody()
57 __Usage of {@link #fieldDefaults}:__
58 {@img Ext.form.FieldContainer/Ext.form.FieldContainer2.png Ext.form.FieldContainer component}
60 Ext.create('Ext.form.Panel', {
61 title: 'FieldContainer Example',
66 xtype: 'fieldcontainer',
67 fieldLabel: 'Your Name',
69 defaultType: 'textfield',
71 // Arrange fields vertically, stretched to full width
77 // These config values will be applied to both sub-fields, except
78 // for Last Name which will use its own msgTarget.
85 fieldLabel: 'First Name',
88 fieldLabel: 'Last Name',
93 renderTo: Ext.getBody()
98 * Creates a new Ext.form.FieldContainer instance.
99 * @param {Object} config The component configuration.
101 * @xtype fieldcontainer
103 * @docauthor Jason Johnston <jason@sencha.com>
105 Ext.define('Ext.form.FieldContainer', {
106 extend: 'Ext.container.Container',
108 labelable: 'Ext.form.Labelable',
109 fieldAncestor: 'Ext.form.FieldAncestor'
111 alias: 'widget.fieldcontainer',
113 componentLayout: 'field',
115 <span id='Ext-form.FieldContainer-cfg-combineLabels'> /**
116 </span> * @cfg {Boolean} combineLabels
117 * If set to true, and there is no defined {@link #fieldLabel}, the field container will automatically
118 * generate its label by combining the labels of all the fields it contains. Defaults to false.
120 combineLabels: false,
122 <span id='Ext-form.FieldContainer-cfg-labelConnector'> /**
123 </span> * @cfg {String} labelConnector
124 * The string to use when joining the labels of individual sub-fields, when {@link #combineLabels} is
125 * set to true. Defaults to ', '.
127 labelConnector: ', ',
129 <span id='Ext-form.FieldContainer-cfg-combineErrors'> /**
130 </span> * @cfg {Boolean} combineErrors
131 * If set to true, the field container will automatically combine and display the validation errors from
132 * all the fields it contains as a single error on the container, according to the configured
133 * {@link #msgTarget}. Defaults to false.
135 combineErrors: false,
137 maskOnDisable: false,
139 initComponent: function() {
141 onSubCmpAddOrRemove = me.onSubCmpAddOrRemove;
145 me.initFieldAncestor();
150 <span id='Ext-form.FieldContainer-method-onLabelableAdded'> /**
151 </span> * @protected Called when a {@link Ext.form.Labelable} instance is added to the container's subtree.
152 * @param {Ext.form.Labelable} labelable The instance that was added
154 onLabelableAdded: function(labelable) {
156 me.mixins.fieldAncestor.onLabelableAdded.call(this, labelable);
160 <span id='Ext-form.FieldContainer-method-onLabelableRemoved'> /**
161 </span> * @protected Called when a {@link Ext.form.Labelable} instance is removed from the container's subtree.
162 * @param {Ext.form.Labelable} labelable The instance that was removed
164 onLabelableRemoved: function(labelable) {
166 me.mixins.fieldAncestor.onLabelableRemoved.call(this, labelable);
170 onRender: function() {
172 renderSelectors = me.renderSelectors,
173 applyIf = Ext.applyIf;
175 applyIf(renderSelectors, me.getLabelableSelectors());
177 me.callParent(arguments);
180 initRenderTpl: function() {
182 if (!me.hasOwnProperty('renderTpl')) {
183 me.renderTpl = me.getTpl('labelableRenderTpl');
185 return me.callParent();
188 initRenderData: function() {
189 return Ext.applyIf(this.callParent(), this.getLabelableRenderData());
192 <span id='Ext-form.FieldContainer-method-getFieldLabel'> /**
193 </span> * Returns the combined field label if {@link #combineLabels} is set to true and if there is no
194 * set {@link #fieldLabel}. Otherwise returns the fieldLabel like normal. You can also override
195 * this method to provide a custom generated label.
197 getFieldLabel: function() {
198 var label = this.fieldLabel || '';
199 if (!label && this.combineLabels) {
200 label = Ext.Array.map(this.query('[isFieldLabelable]'), function(field) {
201 return field.getFieldLabel();
202 }).join(this.labelConnector);
207 <span id='Ext-form.FieldContainer-method-updateLabel'> /**
208 </span> * @private Updates the content of the labelEl if it is rendered
210 updateLabel: function() {
214 label.update(me.getFieldLabel());
219 <span id='Ext-form.FieldContainer-method-onFieldErrorChange'> /**
220 </span> * @private Fired when the error message of any field within the container changes, and updates the
221 * combined error message to match.
223 onFieldErrorChange: function(field, activeError) {
224 if (this.combineErrors) {
226 oldError = me.getActiveError(),
227 invalidFields = Ext.Array.filter(me.query('[isFormField]'), function(field) {
228 return field.hasActiveError();
230 newErrors = me.getCombinedErrors(invalidFields);
233 me.setActiveErrors(newErrors);
235 me.unsetActiveError();
238 if (oldError !== me.getActiveError()) {
239 me.doComponentLayout();
244 <span id='Ext-form.FieldContainer-method-getCombinedErrors'> /**
245 </span> * Takes an Array of invalid {@link Ext.form.field.Field} objects and builds a combined list of error
246 * messages from them. Defaults to prepending each message by the field name and a colon. This
247 * can be overridden to provide custom combined error message handling, for instance changing
248 * the format of each message or sorting the array (it is sorted in order of appearance by default).
249 * @param {Array} invalidFields An Array of the sub-fields which are currently invalid.
250 * @return {Array} The combined list of error messages
252 getCombinedErrors: function(invalidFields) {
253 var forEach = Ext.Array.forEach,
255 forEach(invalidFields, function(field) {
256 forEach(field.getActiveErrors(), function(error) {
257 var label = field.getFieldLabel();
258 errors.push((label ? label + ': ' : '') + error);
264 getTargetEl: function() {
265 return this.bodyEl || this.callParent();
268 </pre></pre></body></html>