4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-form-FieldContainer'>/**
19 </span> * FieldContainer is a derivation of {@link Ext.container.Container Container} that implements the
20 * {@link Ext.form.Labelable Labelable} mixin. This allows it to be configured so that it is rendered with
21 * a {@link #fieldLabel field label} and optional {@link #msgTarget error message} around its sub-items.
22 * This is useful for arranging a group of fields or other components within a single item in a form, so
23 * that it lines up nicely with other fields. A common use is for grouping a set of related fields under
24 * a single label in a form.
26 * The container's configured {@link #items} will be layed out within the field body area according to the
27 * configured {@link #layout} type. The default layout is `'autocontainer'`.
29 * Like regular fields, FieldContainer can inherit its decoration configuration from the
30 * {@link Ext.form.Panel#fieldDefaults fieldDefaults} of an enclosing FormPanel. In addition,
31 * FieldContainer itself can pass {@link #fieldDefaults} to any {@link Ext.form.Labelable fields}
32 * it may itself contain.
34 * If you are grouping a set of {@link Ext.form.field.Checkbox Checkbox} or {@link Ext.form.field.Radio Radio}
35 * fields in a single labeled container, consider using a {@link Ext.form.CheckboxGroup}
36 * or {@link Ext.form.RadioGroup} instead as they are specialized for handling those types.
41 * Ext.create('Ext.form.Panel', {
42 * title: 'FieldContainer Example',
47 * xtype: 'fieldcontainer',
48 * fieldLabel: 'Last Three Jobs',
51 * // The body area will contain three text fields, arranged
52 * // horizontally, separated by draggable splitters.
69 * renderTo: Ext.getBody()
72 * # Usage of fieldDefaults
75 * Ext.create('Ext.form.Panel', {
76 * title: 'FieldContainer Example',
81 * xtype: 'fieldcontainer',
82 * fieldLabel: 'Your Name',
84 * defaultType: 'textfield',
86 * // Arrange fields vertically, stretched to full width
92 * // These config values will be applied to both sub-fields, except
93 * // for Last Name which will use its own msgTarget.
100 * fieldLabel: 'First Name',
103 * fieldLabel: 'Last Name',
108 * renderTo: Ext.getBody()
111 * @docauthor Jason Johnston <jason@sencha.com>
113 Ext.define('Ext.form.FieldContainer', {
114 extend: 'Ext.container.Container',
116 labelable: 'Ext.form.Labelable',
117 fieldAncestor: 'Ext.form.FieldAncestor'
119 alias: 'widget.fieldcontainer',
121 componentLayout: 'field',
123 <span id='Ext-form-FieldContainer-cfg-combineLabels'> /**
124 </span> * @cfg {Boolean} combineLabels
125 * If set to true, and there is no defined {@link #fieldLabel}, the field container will automatically
126 * generate its label by combining the labels of all the fields it contains. Defaults to false.
128 combineLabels: false,
130 <span id='Ext-form-FieldContainer-cfg-labelConnector'> /**
131 </span> * @cfg {String} labelConnector
132 * The string to use when joining the labels of individual sub-fields, when {@link #combineLabels} is
133 * set to true. Defaults to ', '.
135 labelConnector: ', ',
137 <span id='Ext-form-FieldContainer-cfg-combineErrors'> /**
138 </span> * @cfg {Boolean} combineErrors
139 * If set to true, the field container will automatically combine and display the validation errors from
140 * all the fields it contains as a single error on the container, according to the configured
141 * {@link #msgTarget}. Defaults to false.
143 combineErrors: false,
145 maskOnDisable: false,
147 initComponent: function() {
149 onSubCmpAddOrRemove = me.onSubCmpAddOrRemove;
153 me.initFieldAncestor();
158 <span id='Ext-form-FieldContainer-method-onLabelableAdded'> /**
159 </span> * @protected Called when a {@link Ext.form.Labelable} instance is added to the container's subtree.
160 * @param {Ext.form.Labelable} labelable The instance that was added
162 onLabelableAdded: function(labelable) {
164 me.mixins.fieldAncestor.onLabelableAdded.call(this, labelable);
168 <span id='Ext-form-FieldContainer-method-onLabelableRemoved'> /**
169 </span> * @protected Called when a {@link Ext.form.Labelable} instance is removed from the container's subtree.
170 * @param {Ext.form.Labelable} labelable The instance that was removed
172 onLabelableRemoved: function(labelable) {
174 me.mixins.fieldAncestor.onLabelableRemoved.call(this, labelable);
178 onRender: function() {
181 me.onLabelableRender();
183 me.callParent(arguments);
186 initRenderTpl: function() {
188 if (!me.hasOwnProperty('renderTpl')) {
189 me.renderTpl = me.getTpl('labelableRenderTpl');
191 return me.callParent();
194 initRenderData: function() {
195 return Ext.applyIf(this.callParent(), this.getLabelableRenderData());
198 <span id='Ext-form-FieldContainer-method-getFieldLabel'> /**
199 </span> * Returns the combined field label if {@link #combineLabels} is set to true and if there is no
200 * set {@link #fieldLabel}. Otherwise returns the fieldLabel like normal. You can also override
201 * this method to provide a custom generated label.
203 getFieldLabel: function() {
204 var label = this.fieldLabel || '';
205 if (!label && this.combineLabels) {
206 label = Ext.Array.map(this.query('[isFieldLabelable]'), function(field) {
207 return field.getFieldLabel();
208 }).join(this.labelConnector);
213 <span id='Ext-form-FieldContainer-method-updateLabel'> /**
214 </span> * @private Updates the content of the labelEl if it is rendered
216 updateLabel: function() {
220 label.update(me.getFieldLabel());
225 <span id='Ext-form-FieldContainer-method-onFieldErrorChange'> /**
226 </span> * @private Fired when the error message of any field within the container changes, and updates the
227 * combined error message to match.
229 onFieldErrorChange: function(field, activeError) {
230 if (this.combineErrors) {
232 oldError = me.getActiveError(),
233 invalidFields = Ext.Array.filter(me.query('[isFormField]'), function(field) {
234 return field.hasActiveError();
236 newErrors = me.getCombinedErrors(invalidFields);
239 me.setActiveErrors(newErrors);
241 me.unsetActiveError();
244 if (oldError !== me.getActiveError()) {
245 me.doComponentLayout();
250 <span id='Ext-form-FieldContainer-method-getCombinedErrors'> /**
251 </span> * Takes an Array of invalid {@link Ext.form.field.Field} objects and builds a combined list of error
252 * messages from them. Defaults to prepending each message by the field name and a colon. This
253 * can be overridden to provide custom combined error message handling, for instance changing
254 * the format of each message or sorting the array (it is sorted in order of appearance by default).
255 * @param {Ext.form.field.Field[]} invalidFields An Array of the sub-fields which are currently invalid.
256 * @return {String[]} The combined list of error messages
258 getCombinedErrors: function(invalidFields) {
259 var forEach = Ext.Array.forEach,
261 forEach(invalidFields, function(field) {
262 forEach(field.getActiveErrors(), function(error) {
263 var label = field.getFieldLabel();
264 errors.push((label ? label + ': ' : '') + error);
270 getTargetEl: function() {
271 return this.bodyEl || this.callParent();