4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../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-FieldAncestor'>/**
19 </span> * @class Ext.form.FieldAncestor
21 A mixin for {@link Ext.container.Container} components that are likely to have form fields in their
22 items subtree. Adds the following capabilities:
24 - Methods for handling the addition and removal of {@link Ext.form.Labelable} and {@link Ext.form.field.Field}
25 instances at any depth within the container.
26 - Events ({@link #fieldvaliditychange} and {@link #fielderrorchange}) for handling changes to the state
27 of individual fields at the container level.
28 - Automatic application of {@link #fieldDefaults} config properties to each field added within the
29 container, to facilitate uniform configuration of all fields.
31 This mixin is primarily for internal use by {@link Ext.form.Panel} and {@link Ext.form.FieldContainer},
32 and should not normally need to be used directly.
35 * @docauthor Jason Johnston <jason@sencha.com>
37 Ext.define('Ext.form.FieldAncestor', {
39 <span id='Ext-form-FieldAncestor-cfg-fieldDefaults'> /**
40 </span> * @cfg {Object} fieldDefaults
41 * <p>If specified, the properties in this object are used as default config values for each
42 * {@link Ext.form.Labelable} instance (e.g. {@link Ext.form.field.Base} or {@link Ext.form.FieldContainer})
43 * that is added as a descendant of this container. Corresponding values specified in an individual field's
44 * own configuration, or from the {@link Ext.container.Container#defaults defaults config} of its parent container,
45 * will take precedence. See the documentation for {@link Ext.form.Labelable} to see what config
46 * options may be specified in the <tt>fieldDefaults</tt>.</p>
47 * <p>Example:</p>
48 * <pre><code>new Ext.form.Panel({
72 });</code></pre>
73 * <p>In this example, field1 and field2 will get labelAlign:'top' (from the fieldset's <tt>defaults</tt>)
74 * and labelWidth:100 (from <tt>fieldDefaults</tt>), field3 and field4 will both get labelAlign:'left' (from
75 * <tt>fieldDefaults</tt> and field3 will use the labelWidth:150 from its own config.</p>
79 <span id='Ext-form-FieldAncestor-method-initFieldAncestor'> /**
80 </span> * @protected Initializes the FieldAncestor's state; this must be called from the initComponent method
81 * of any components importing this mixin.
83 initFieldAncestor: function() {
85 onSubtreeChange = me.onFieldAncestorSubtreeChange;
88 <span id='Ext-form-FieldAncestor-event-fielderrorchange'> /**
89 </span> * @event fielderrorchange
90 * Fires when the validity state of any one of the {@link Ext.form.field.Field} instances within this
92 * @param {Ext.form.FieldAncestor} this
93 * @param {Ext.form.Labelable} The Field instance whose validity changed
94 * @param {String} isValid The field's new validity state
96 'fieldvaliditychange',
98 <span id='Ext-form-FieldAncestor-event-fielderrorchange'> /**
99 </span> * @event fielderrorchange
100 * Fires when the active error message is changed for any one of the {@link Ext.form.Labelable}
101 * instances within this container.
102 * @param {Ext.form.FieldAncestor} this
103 * @param {Ext.form.Labelable} The Labelable instance whose active error was changed
104 * @param {String} error The active error message
109 // Catch addition and removal of descendant fields
110 me.on('add', onSubtreeChange, me);
111 me.on('remove', onSubtreeChange, me);
113 me.initFieldDefaults();
116 <span id='Ext-form-FieldAncestor-method-initFieldDefaults'> /**
117 </span> * @private Initialize the {@link #fieldDefaults} object
119 initFieldDefaults: function() {
120 if (!this.fieldDefaults) {
121 this.fieldDefaults = {};
125 <span id='Ext-form-FieldAncestor-method-onFieldAncestorSubtreeChange'> /**
127 * Handle the addition and removal of components in the FieldAncestor component's child tree.
129 onFieldAncestorSubtreeChange: function(parent, child) {
131 isAdding = !!child.ownerCt;
133 function handleCmp(cmp) {
134 var isLabelable = cmp.isFieldLabelable,
135 isField = cmp.isFormField;
136 if (isLabelable || isField) {
138 me['onLabelable' + (isAdding ? 'Added' : 'Removed')](cmp);
141 me['onField' + (isAdding ? 'Added' : 'Removed')](cmp);
144 else if (cmp.isContainer) {
145 Ext.Array.forEach(cmp.getRefItems(), handleCmp);
151 <span id='Ext-form-FieldAncestor-method-onLabelableAdded'> /**
152 </span> * @protected Called when a {@link Ext.form.Labelable} instance is added to the container's subtree.
153 * @param {Ext.form.Labelable} labelable The instance that was added
155 onLabelableAdded: function(labelable) {
158 // buffer slightly to avoid excessive firing while sub-fields are changing en masse
159 me.mon(labelable, 'errorchange', me.handleFieldErrorChange, me, {buffer: 10});
161 labelable.setFieldDefaults(me.fieldDefaults);
164 <span id='Ext-form-FieldAncestor-method-onFieldAdded'> /**
165 </span> * @protected Called when a {@link Ext.form.field.Field} instance is added to the container's subtree.
166 * @param {Ext.form.field.Field} field The field which was added
168 onFieldAdded: function(field) {
170 me.mon(field, 'validitychange', me.handleFieldValidityChange, me);
173 <span id='Ext-form-FieldAncestor-method-onLabelableRemoved'> /**
174 </span> * @protected Called when a {@link Ext.form.Labelable} instance is removed from the container's subtree.
175 * @param {Ext.form.Labelable} labelable The instance that was removed
177 onLabelableRemoved: function(labelable) {
179 me.mun(labelable, 'errorchange', me.handleFieldErrorChange, me);
182 <span id='Ext-form-FieldAncestor-method-onFieldRemoved'> /**
183 </span> * @protected Called when a {@link Ext.form.field.Field} instance is removed from the container's subtree.
184 * @param {Ext.form.field.Field} field The field which was removed
186 onFieldRemoved: function(field) {
188 me.mun(field, 'validitychange', me.handleFieldValidityChange, me);
191 <span id='Ext-form-FieldAncestor-method-handleFieldValidityChange'> /**
192 </span> * @private Handle validitychange events on sub-fields; invoke the aggregated event and method
194 handleFieldValidityChange: function(field, isValid) {
196 me.fireEvent('fieldvaliditychange', me, field, isValid);
197 me.onFieldValidityChange();
200 <span id='Ext-form-FieldAncestor-method-handleFieldErrorChange'> /**
201 </span> * @private Handle errorchange events on sub-fields; invoke the aggregated event and method
203 handleFieldErrorChange: function(labelable, activeError) {
205 me.fireEvent('fielderrorchange', me, labelable, activeError);
206 me.onFieldErrorChange();
209 <span id='Ext-form-FieldAncestor-property-onFieldValidityChange'> /**
210 </span> * @protected Fired when the validity of any field within the container changes.
211 * @param {Ext.form.field.Field} The sub-field whose validity changed
212 * @param {String} The new validity state
214 onFieldValidityChange: Ext.emptyFn,
216 <span id='Ext-form-FieldAncestor-property-onFieldErrorChange'> /**
217 </span> * @protected Fired when the error message of any field within the container changes.
218 * @param {Ext.form.Labelable} The sub-field whose active error changed
219 * @param {String} The new active error message
221 onFieldErrorChange: Ext.emptyFn