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-Panel'>/**
19 </span> * @class Ext.form.Panel
20 * @extends Ext.panel.Panel
22 FormPanel provides a standard container for forms. It is essentially a standard {@link Ext.panel.Panel} which
23 automatically creates a {@link Ext.form.Basic BasicForm} for managing any {@link Ext.form.field.Field}
24 objects that are added as descendants of the panel. It also includes conveniences for configuring and
25 working with the BasicForm and the collection of Fields.
29 By default, FormPanel is configured with `{@link Ext.layout.container.Anchor layout:'anchor'}` for
30 the layout of its immediate child items. This can be changed to any of the supported container layouts.
31 The layout of sub-containers is configured in {@link Ext.container.Container#layout the standard way}.
35 Although **not listed** as configuration options of FormPanel, the FormPanel class accepts all
36 of the config options supported by the {@link Ext.form.Basic} class, and will pass them along to
37 the internal BasicForm when it is created.
39 **Note**: If subclassing FormPanel, any configuration options for the BasicForm must be applied to
40 the `initialConfig` property of the FormPanel. Applying {@link Ext.form.Basic BasicForm}
41 configuration settings to `this` will *not* affect the BasicForm's configuration.
43 The following events fired by the BasicForm will be re-fired by the FormPanel and can therefore be
44 listened for on the FormPanel itself:
46 - {@link Ext.form.Basic#beforeaction beforeaction}
47 - {@link Ext.form.Basic#actionfailed actionfailed}
48 - {@link Ext.form.Basic#actioncomplete actioncomplete}
49 - {@link Ext.form.Basic#validitychange validitychange}
50 - {@link Ext.form.Basic#dirtychange dirtychange}
54 The {@link #fieldDefaults} config option conveniently allows centralized configuration of default values
55 for all fields added as descendants of the FormPanel. Any config option recognized by implementations
56 of {@link Ext.form.Labelable} may be included in this object. See the {@link #fieldDefaults} documentation
57 for details of how the defaults are applied.
61 With the default configuration, form fields are validated on-the-fly while the user edits their values.
62 This can be controlled on a per-field basis (or via the {@link #fieldDefaults} config) with the field
63 config properties {@link Ext.form.field.Field#validateOnChange} and {@link Ext.form.field.Base#checkChangeEvents},
64 and the FormPanel's config properties {@link #pollForChanges} and {@link #pollInterval}.
66 Any component within the FormPanel can be configured with `formBind: true`. This will cause that
67 component to be automatically disabled when the form is invalid, and enabled when it is valid. This is most
68 commonly used for Button components to prevent submitting the form in an invalid state, but can be used on
71 For more information on form validation see the following:
73 - {@link Ext.form.field.Field#validateOnChange}
74 - {@link #pollForChanges} and {@link #pollInterval}
75 - {@link Ext.form.field.VTypes}
76 - {@link Ext.form.Basic#doAction BasicForm.doAction clientValidation notes}
80 By default, Ext Forms are submitted through Ajax, using {@link Ext.form.action.Action}. See the documentation for
81 {@link Ext.form.Basic} for details.
82 {@img Ext.form.FormPanel/Ext.form.FormPanel.png Ext.form.FormPanel FormPanel component}
85 Ext.create('Ext.form.Panel', {
90 // The form will submit an AJAX request to this URL when submitted
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()
140 * @docauthor Jason Johnston <jason@sencha.com>
142 Ext.define('Ext.form.Panel', {
143 extend:'Ext.panel.Panel',
145 fieldAncestor: 'Ext.form.FieldAncestor'
147 alias: 'widget.form',
148 alternateClassName: ['Ext.FormPanel', 'Ext.form.FormPanel'],
149 requires: ['Ext.form.Basic', 'Ext.util.TaskRunner'],
151 <span id='Ext-form-Panel-cfg-pollForChanges'> /**
152 </span> * @cfg {Boolean} pollForChanges
153 * If set to <tt>true</tt>, sets up an interval task (using the {@link #pollInterval}) in which the
154 * panel's fields are repeatedly checked for changes in their values. This is in addition to the normal detection
155 * each field does on its own input element, and is not needed in most cases. It does, however, provide a
156 * means to absolutely guarantee detection of all changes including some edge cases in some browsers which
157 * do not fire native events. Defaults to <tt>false</tt>.
160 <span id='Ext-form-Panel-cfg-pollInterval'> /**
161 </span> * @cfg {Number} pollInterval
162 * Interval in milliseconds at which the form's fields are checked for value changes. Only used if
163 * the {@link #pollForChanges} option is set to <tt>true</tt>. Defaults to 500 milliseconds.
166 <span id='Ext-form-Panel-cfg-layout'> /**
167 </span> * @cfg {String} layout The {@link Ext.container.Container#layout} for the form panel's immediate child items.
168 * Defaults to <tt>'anchor'</tt>.
174 initComponent: function() {
181 me.initFieldAncestor();
184 me.relayEvents(me.form, [
192 // Start polling if configured
193 if (me.pollForChanges) {
194 me.startPolling(me.pollInterval || 500);
198 initItems: function() {
199 // Create the BasicForm
202 me.form = me.createForm();
204 me.form.initialize();
207 <span id='Ext-form-Panel-method-createForm'> /**
210 createForm: function() {
211 return Ext.create('Ext.form.Basic', this, Ext.applyIf({listeners: {}}, this.initialConfig));
214 <span id='Ext-form-Panel-method-getForm'> /**
215 </span> * Provides access to the {@link Ext.form.Basic Form} which this Panel contains.
216 * @return {Ext.form.Basic} The {@link Ext.form.Basic Form} which this Panel contains.
218 getForm: function() {
222 <span id='Ext-form-Panel-method-loadRecord'> /**
223 </span> * Loads an {@link Ext.data.Model} into this form (internally just calls {@link Ext.form.Basic#loadRecord})
224 * See also {@link #trackResetOnLoad}.
225 * @param {Ext.data.Model} record The record to load
226 * @return {Ext.form.Basic} The Ext.form.Basic attached to this FormPanel
228 loadRecord: function(record) {
229 return this.getForm().loadRecord(record);
232 <span id='Ext-form-Panel-method-getRecord'> /**
233 </span> * Returns the currently loaded Ext.data.Model instance if one was loaded via {@link #loadRecord}.
234 * @return {Ext.data.Model} The loaded instance
236 getRecord: function() {
237 return this.getForm().getRecord();
240 <span id='Ext-form-Panel-method-getValues'> /**
241 </span> * Convenience function for fetching the current value of each field in the form. This is the same as calling
242 * {@link Ext.form.Basic#getValues this.getForm().getValues()}
243 * @return {Object} The current form field values, keyed by field name
245 getValues: function() {
246 return this.getForm().getValues();
249 beforeDestroy: function() {
255 <span id='Ext-form-Panel-method-load'> /**
256 </span> * This is a proxy for the underlying BasicForm's {@link Ext.form.Basic#load} call.
257 * @param {Object} options The options to pass to the action (see {@link Ext.form.Basic#load} and
258 * {@link Ext.form.Basic#doAction} for details)
260 load: function(options) {
261 this.form.load(options);
264 <span id='Ext-form-Panel-method-submit'> /**
265 </span> * This is a proxy for the underlying BasicForm's {@link Ext.form.Basic#submit} call.
266 * @param {Object} options The options to pass to the action (see {@link Ext.form.Basic#submit} and
267 * {@link Ext.form.Basic#doAction} for details)
269 submit: function(options) {
270 this.form.submit(options);
274 * Inherit docs, not using onDisable because it only gets fired
275 * when the component is rendered.
277 disable: function(silent) {
278 this.callParent(arguments);
279 this.form.getFields().each(function(field) {
285 * Inherit docs, not using onEnable because it only gets fired
286 * when the component is rendered.
288 enable: function(silent) {
289 this.callParent(arguments);
290 this.form.getFields().each(function(field) {
295 <span id='Ext-form-Panel-method-startPolling'> /**
296 </span> * Start an interval task to continuously poll all the fields in the form for changes in their
297 * values. This is normally started automatically by setting the {@link #pollForChanges} config.
298 * @param {Number} interval The interval in milliseconds at which the check should run.
300 startPolling: function(interval) {
302 var task = Ext.create('Ext.util.TaskRunner', interval);
305 run: this.checkChange,
308 this.pollTask = task;
311 <span id='Ext-form-Panel-method-stopPolling'> /**
312 </span> * Stop a running interval task that was started by {@link #startPolling}.
314 stopPolling: function() {
315 var task = this.pollTask;
318 delete this.pollTask;
322 <span id='Ext-form-Panel-method-checkChange'> /**
323 </span> * Forces each field within the form panel to
324 * {@link Ext.form.field.Field#checkChange check if its value has changed}.
326 checkChange: function() {
327 this.form.getFields().each(function(field) {