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-Panel'>/**
19 </span> * @docauthor Jason Johnston <jason@sencha.com>
21 * FormPanel provides a standard container for forms. It is essentially a standard {@link Ext.panel.Panel} which
22 * automatically creates a {@link Ext.form.Basic BasicForm} for managing any {@link Ext.form.field.Field}
23 * objects that are added as descendants of the panel. It also includes conveniences for configuring and
24 * working with the BasicForm and the collection of Fields.
28 * By default, FormPanel is configured with `{@link Ext.layout.container.Anchor layout:'anchor'}` for
29 * the layout of its immediate child items. This can be changed to any of the supported container layouts.
30 * The layout of sub-containers is configured in {@link Ext.container.Container#layout the standard way}.
34 * Although **not listed** as configuration options of FormPanel, the FormPanel class accepts all
35 * of the config options supported by the {@link Ext.form.Basic} class, and will pass them along to
36 * the internal BasicForm when it is created.
38 * **Note**: If subclassing FormPanel, any configuration options for the BasicForm must be applied to
39 * the `initialConfig` property of the FormPanel. Applying {@link Ext.form.Basic BasicForm}
40 * configuration settings to `this` will *not* affect the BasicForm's configuration.
42 * The following events fired by the BasicForm will be re-fired by the FormPanel and can therefore be
43 * listened for on the FormPanel itself:
45 * - {@link Ext.form.Basic#beforeaction beforeaction}
46 * - {@link Ext.form.Basic#actionfailed actionfailed}
47 * - {@link Ext.form.Basic#actioncomplete actioncomplete}
48 * - {@link Ext.form.Basic#validitychange validitychange}
49 * - {@link Ext.form.Basic#dirtychange dirtychange}
53 * The {@link #fieldDefaults} config option conveniently allows centralized configuration of default values
54 * for all fields added as descendants of the FormPanel. Any config option recognized by implementations
55 * of {@link Ext.form.Labelable} may be included in this object. See the {@link #fieldDefaults} documentation
56 * for details of how the defaults are applied.
60 * With the default configuration, form fields are validated on-the-fly while the user edits their values.
61 * This can be controlled on a per-field basis (or via the {@link #fieldDefaults} config) with the field
62 * config properties {@link Ext.form.field.Field#validateOnChange} and {@link Ext.form.field.Base#checkChangeEvents},
63 * and the FormPanel's config properties {@link #pollForChanges} and {@link #pollInterval}.
65 * Any component within the FormPanel can be configured with `formBind: true`. This will cause that
66 * component to be automatically disabled when the form is invalid, and enabled when it is valid. This is most
67 * commonly used for Button components to prevent submitting the form in an invalid state, but can be used on
70 * For more information on form validation see the following:
72 * - {@link Ext.form.field.Field#validateOnChange}
73 * - {@link #pollForChanges} and {@link #pollInterval}
74 * - {@link Ext.form.field.VTypes}
75 * - {@link Ext.form.Basic#doAction BasicForm.doAction clientValidation notes}
79 * By default, Ext Forms are submitted through Ajax, using {@link Ext.form.action.Action}. See the documentation for
80 * {@link Ext.form.Basic} for details.
85 * Ext.create('Ext.form.Panel', {
86 * title: 'Simple Form',
90 * // The form will submit an AJAX request to this URL when submitted
91 * url: 'save-form.php',
93 * // Fields will be arranged vertically, stretched to full width
100 * defaultType: 'textfield',
102 * fieldLabel: 'First Name',
106 * fieldLabel: 'Last Name',
111 * // Reset and Submit buttons
114 * handler: function() {
115 * this.up('form').getForm().reset();
119 * formBind: true, //only enabled once the form is valid
121 * handler: function() {
122 * var form = this.up('form').getForm();
123 * if (form.isValid()) {
125 * success: function(form, action) {
126 * Ext.Msg.alert('Success', action.result.msg);
128 * failure: function(form, action) {
129 * Ext.Msg.alert('Failed', action.result.msg);
135 * renderTo: Ext.getBody()
139 Ext.define('Ext.form.Panel', {
140 extend:'Ext.panel.Panel',
142 fieldAncestor: 'Ext.form.FieldAncestor'
144 alias: 'widget.form',
145 alternateClassName: ['Ext.FormPanel', 'Ext.form.FormPanel'],
146 requires: ['Ext.form.Basic', 'Ext.util.TaskRunner'],
148 <span id='Ext-form-Panel-cfg-pollForChanges'> /**
149 </span> * @cfg {Boolean} pollForChanges
150 * If set to `true`, sets up an interval task (using the {@link #pollInterval}) in which the
151 * panel's fields are repeatedly checked for changes in their values. This is in addition to the normal detection
152 * each field does on its own input element, and is not needed in most cases. It does, however, provide a
153 * means to absolutely guarantee detection of all changes including some edge cases in some browsers which
154 * do not fire native events. Defaults to `false`.
157 <span id='Ext-form-Panel-cfg-pollInterval'> /**
158 </span> * @cfg {Number} pollInterval
159 * Interval in milliseconds at which the form's fields are checked for value changes. Only used if
160 * the {@link #pollForChanges} option is set to `true`. Defaults to 500 milliseconds.
163 <span id='Ext-form-Panel-cfg-layout'> /**
164 </span> * @cfg {String} layout
165 * The {@link Ext.container.Container#layout} for the form panel's immediate child items.
166 * Defaults to `'anchor'`.
172 initComponent: function() {
179 me.initFieldAncestor();
182 me.relayEvents(me.form, [
190 // Start polling if configured
191 if (me.pollForChanges) {
192 me.startPolling(me.pollInterval || 500);
196 initItems: function() {
197 // Create the BasicForm
200 me.form = me.createForm();
202 me.form.initialize();
205 <span id='Ext-form-Panel-method-createForm'> /**
208 createForm: function() {
209 return Ext.create('Ext.form.Basic', this, Ext.applyIf({listeners: {}}, this.initialConfig));
212 <span id='Ext-form-Panel-method-getForm'> /**
213 </span> * Provides access to the {@link Ext.form.Basic Form} which this Panel contains.
214 * @return {Ext.form.Basic} The {@link Ext.form.Basic Form} which this Panel contains.
216 getForm: function() {
220 <span id='Ext-form-Panel-method-loadRecord'> /**
221 </span> * Loads an {@link Ext.data.Model} into this form (internally just calls {@link Ext.form.Basic#loadRecord})
222 * See also {@link Ext.form.Basic#trackResetOnLoad trackResetOnLoad}.
223 * @param {Ext.data.Model} record The record to load
224 * @return {Ext.form.Basic} The Ext.form.Basic attached to this FormPanel
226 loadRecord: function(record) {
227 return this.getForm().loadRecord(record);
230 <span id='Ext-form-Panel-method-getRecord'> /**
231 </span> * Returns the currently loaded Ext.data.Model instance if one was loaded via {@link #loadRecord}.
232 * @return {Ext.data.Model} The loaded instance
234 getRecord: function() {
235 return this.getForm().getRecord();
238 <span id='Ext-form-Panel-method-getValues'> /**
239 </span> * Convenience function for fetching the current value of each field in the form. This is the same as calling
240 * {@link Ext.form.Basic#getValues this.getForm().getValues()}
241 * @return {Object} The current form field values, keyed by field name
243 getValues: function() {
244 return this.getForm().getValues();
247 beforeDestroy: function() {
253 <span id='Ext-form-Panel-method-load'> /**
254 </span> * This is a proxy for the underlying BasicForm's {@link Ext.form.Basic#load} call.
255 * @param {Object} options The options to pass to the action (see {@link Ext.form.Basic#load} and
256 * {@link Ext.form.Basic#doAction} for details)
258 load: function(options) {
259 this.form.load(options);
262 <span id='Ext-form-Panel-method-submit'> /**
263 </span> * This is a proxy for the underlying BasicForm's {@link Ext.form.Basic#submit} call.
264 * @param {Object} options The options to pass to the action (see {@link Ext.form.Basic#submit} and
265 * {@link Ext.form.Basic#doAction} for details)
267 submit: function(options) {
268 this.form.submit(options);
272 * Inherit docs, not using onDisable because it only gets fired
273 * when the component is rendered.
275 disable: function(silent) {
276 this.callParent(arguments);
277 this.form.getFields().each(function(field) {
283 * Inherit docs, not using onEnable because it only gets fired
284 * when the component is rendered.
286 enable: function(silent) {
287 this.callParent(arguments);
288 this.form.getFields().each(function(field) {
293 <span id='Ext-form-Panel-method-startPolling'> /**
294 </span> * Start an interval task to continuously poll all the fields in the form for changes in their
295 * values. This is normally started automatically by setting the {@link #pollForChanges} config.
296 * @param {Number} interval The interval in milliseconds at which the check should run.
298 startPolling: function(interval) {
300 var task = Ext.create('Ext.util.TaskRunner', interval);
303 run: this.checkChange,
306 this.pollTask = task;
309 <span id='Ext-form-Panel-method-stopPolling'> /**
310 </span> * Stop a running interval task that was started by {@link #startPolling}.
312 stopPolling: function() {
313 var task = this.pollTask;
316 delete this.pollTask;
320 <span id='Ext-form-Panel-method-checkChange'> /**
321 </span> * Forces each field within the form panel to
322 * {@link Ext.form.field.Field#checkChange check if its value has changed}.
324 checkChange: function() {
325 this.form.getFields().each(function(field) {