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-method-constructor'><span id='Ext-form-Panel'>/**
19 </span></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()
139 * @param {Object} config Configuration options
143 * @docauthor Jason Johnston <jason@sencha.com>
145 Ext.define('Ext.form.Panel', {
146 extend:'Ext.panel.Panel',
148 fieldAncestor: 'Ext.form.FieldAncestor'
150 alias: 'widget.form',
151 alternateClassName: ['Ext.FormPanel', 'Ext.form.FormPanel'],
152 requires: ['Ext.form.Basic', 'Ext.util.TaskRunner'],
154 <span id='Ext-form-Panel-cfg-pollForChanges'> /**
155 </span> * @cfg {Boolean} pollForChanges
156 * If set to <tt>true</tt>, sets up an interval task (using the {@link #pollInterval}) in which the
157 * panel's fields are repeatedly checked for changes in their values. This is in addition to the normal detection
158 * each field does on its own input element, and is not needed in most cases. It does, however, provide a
159 * means to absolutely guarantee detection of all changes including some edge cases in some browsers which
160 * do not fire native events. Defaults to <tt>false</tt>.
163 <span id='Ext-form-Panel-cfg-pollInterval'> /**
164 </span> * @cfg {Number} pollInterval
165 * Interval in milliseconds at which the form's fields are checked for value changes. Only used if
166 * the {@link #pollForChanges} option is set to <tt>true</tt>. Defaults to 500 milliseconds.
169 <span id='Ext-form-Panel-cfg-layout'> /**
170 </span> * @cfg {String} layout The {@link Ext.container.Container#layout} for the form panel's immediate child items.
171 * Defaults to <tt>'anchor'</tt>.
177 initComponent: function() {
184 me.initFieldAncestor();
187 me.relayEvents(me.form, [
195 // Start polling if configured
196 if (me.pollForChanges) {
197 me.startPolling(me.pollInterval || 500);
201 initItems: function() {
202 // Create the BasicForm
205 me.form = me.createForm();
207 me.form.initialize();
210 <span id='Ext-form-Panel-method-createForm'> /**
213 createForm: function() {
214 return Ext.create('Ext.form.Basic', this, Ext.applyIf({listeners: {}}, this.initialConfig));
217 <span id='Ext-form-Panel-method-getForm'> /**
218 </span> * Provides access to the {@link Ext.form.Basic Form} which this Panel contains.
219 * @return {Ext.form.Basic} The {@link Ext.form.Basic Form} which this Panel contains.
221 getForm: function() {
225 <span id='Ext-form-Panel-method-loadRecord'> /**
226 </span> * Loads an {@link Ext.data.Model} into this form (internally just calls {@link Ext.form.Basic#loadRecord})
227 * See also {@link #trackResetOnLoad}.
228 * @param {Ext.data.Model} record The record to load
229 * @return {Ext.form.Basic} The Ext.form.Basic attached to this FormPanel
231 loadRecord: function(record) {
232 return this.getForm().loadRecord(record);
235 <span id='Ext-form-Panel-method-getRecord'> /**
236 </span> * Returns the currently loaded Ext.data.Model instance if one was loaded via {@link #loadRecord}.
237 * @return {Ext.data.Model} The loaded instance
239 getRecord: function() {
240 return this.getForm().getRecord();
243 <span id='Ext-form-Panel-method-getValues'> /**
244 </span> * Convenience function for fetching the current value of each field in the form. This is the same as calling
245 * {@link Ext.form.Basic#getValues this.getForm().getValues()}
246 * @return {Object} The current form field values, keyed by field name
248 getValues: function() {
249 return this.getForm().getValues();
252 beforeDestroy: function() {
258 <span id='Ext-form-Panel-method-load'> /**
259 </span> * This is a proxy for the underlying BasicForm's {@link Ext.form.Basic#load} call.
260 * @param {Object} options The options to pass to the action (see {@link Ext.form.Basic#load} and
261 * {@link Ext.form.Basic#doAction} for details)
263 load: function(options) {
264 this.form.load(options);
267 <span id='Ext-form-Panel-method-submit'> /**
268 </span> * This is a proxy for the underlying BasicForm's {@link Ext.form.Basic#submit} call.
269 * @param {Object} options The options to pass to the action (see {@link Ext.form.Basic#submit} and
270 * {@link Ext.form.Basic#doAction} for details)
272 submit: function(options) {
273 this.form.submit(options);
277 * Inherit docs, not using onDisable because it only gets fired
278 * when the component is rendered.
280 disable: function(silent) {
281 this.callParent(arguments);
282 this.form.getFields().each(function(field) {
288 * Inherit docs, not using onEnable because it only gets fired
289 * when the component is rendered.
291 enable: function(silent) {
292 this.callParent(arguments);
293 this.form.getFields().each(function(field) {
298 <span id='Ext-form-Panel-method-startPolling'> /**
299 </span> * Start an interval task to continuously poll all the fields in the form for changes in their
300 * values. This is normally started automatically by setting the {@link #pollForChanges} config.
301 * @param {Number} interval The interval in milliseconds at which the check should run.
303 startPolling: function(interval) {
305 var task = Ext.create('Ext.util.TaskRunner', interval);
308 run: this.checkChange,
311 this.pollTask = task;
314 <span id='Ext-form-Panel-method-stopPolling'> /**
315 </span> * Stop a running interval task that was started by {@link #startPolling}.
317 stopPolling: function() {
318 var task = this.pollTask;
321 delete this.pollTask;
325 <span id='Ext-form-Panel-method-checkChange'> /**
326 </span> * Forces each field within the form panel to
327 * {@link Ext.form.field.Field#checkChange check if its value has changed}.
329 checkChange: function() {
330 this.form.getFields().each(function(field) {