1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-form.Panel-method-constructor'><span id='Ext-form.Panel'>/**
2 </span></span> * @class Ext.form.Panel
3 * @extends Ext.panel.Panel
5 FormPanel provides a standard container for forms. It is essentially a standard {@link Ext.panel.Panel} which
6 automatically creates a {@link Ext.form.Basic BasicForm} for managing any {@link Ext.form.field.Field}
7 objects that are added as descendants of the panel. It also includes conveniences for configuring and
8 working with the BasicForm and the collection of Fields.
12 By default, FormPanel is configured with `{@link Ext.layout.container.Anchor layout:'anchor'}` for
13 the layout of its immediate child items. This can be changed to any of the supported container layouts.
14 The layout of sub-containers is configured in {@link Ext.container.Container#layout the standard way}.
18 Although **not listed** as configuration options of FormPanel, the FormPanel class accepts all
19 of the config options supported by the {@link Ext.form.Basic} class, and will pass them along to
20 the internal BasicForm when it is created.
22 **Note**: If subclassing FormPanel, any configuration options for the BasicForm must be applied to
23 the `initialConfig` property of the FormPanel. Applying {@link Ext.form.Basic BasicForm}
24 configuration settings to `this` will *not* affect the BasicForm's configuration.
26 The following events fired by the BasicForm will be re-fired by the FormPanel and can therefore be
27 listened for on the FormPanel itself:
29 - {@link Ext.form.Basic#beforeaction beforeaction}
30 - {@link Ext.form.Basic#actionfailed actionfailed}
31 - {@link Ext.form.Basic#actioncomplete actioncomplete}
32 - {@link Ext.form.Basic#validitychange validitychange}
33 - {@link Ext.form.Basic#dirtychange dirtychange}
37 The {@link #fieldDefaults} config option conveniently allows centralized configuration of default values
38 for all fields added as descendants of the FormPanel. Any config option recognized by implementations
39 of {@link Ext.form.Labelable} may be included in this object. See the {@link #fieldDefaults} documentation
40 for details of how the defaults are applied.
44 With the default configuration, form fields are validated on-the-fly while the user edits their values.
45 This can be controlled on a per-field basis (or via the {@link #fieldDefaults} config) with the field
46 config properties {@link Ext.form.field.Field#validateOnChange} and {@link Ext.form.field.Base#checkChangeEvents},
47 and the FormPanel's config properties {@link #pollForChanges} and {@link #pollInterval}.
49 Any component within the FormPanel can be configured with `formBind: true`. This will cause that
50 component to be automatically disabled when the form is invalid, and enabled when it is valid. This is most
51 commonly used for Button components to prevent submitting the form in an invalid state, but can be used on
54 For more information on form validation see the following:
56 - {@link Ext.form.field.Field#validateOnChange}
57 - {@link #pollForChanges} and {@link #pollInterval}
58 - {@link Ext.form.field.VTypes}
59 - {@link Ext.form.Basic#doAction BasicForm.doAction clientValidation notes}
63 By default, Ext Forms are submitted through Ajax, using {@link Ext.form.action.Action}. See the documentation for
64 {@link Ext.form.Basic} for details.
65 {@img Ext.form.FormPanel/Ext.form.FormPanel.png Ext.form.FormPanel FormPanel component}
68 Ext.create('Ext.form.Panel', {
73 // The form will submit an AJAX request to this URL when submitted
76 // Fields will be arranged vertically, stretched to full width
83 defaultType: 'textfield',
85 fieldLabel: 'First Name',
89 fieldLabel: 'Last Name',
94 // Reset and Submit buttons
98 this.up('form').getForm().reset();
102 formBind: true, //only enabled once the form is valid
104 handler: function() {
105 var form = this.up('form').getForm();
106 if (form.isValid()) {
108 success: function(form, action) {
109 Ext.Msg.alert('Success', action.result.msg);
111 failure: function(form, action) {
112 Ext.Msg.alert('Failed', action.result.msg);
118 renderTo: Ext.getBody()
122 * @param {Object} config Configuration options
126 * @docauthor Jason Johnston <jason@sencha.com>
128 Ext.define('Ext.form.Panel', {
129 extend:'Ext.panel.Panel',
131 fieldAncestor: 'Ext.form.FieldAncestor'
133 alias: 'widget.form',
134 alternateClassName: ['Ext.FormPanel', 'Ext.form.FormPanel'],
135 requires: ['Ext.form.Basic', 'Ext.util.TaskRunner'],
137 <span id='Ext-form.Panel-cfg-pollForChanges'> /**
138 </span> * @cfg {Boolean} pollForChanges
139 * If set to <tt>true</tt>, sets up an interval task (using the {@link #pollInterval}) in which the
140 * panel's fields are repeatedly checked for changes in their values. This is in addition to the normal detection
141 * each field does on its own input element, and is not needed in most cases. It does, however, provide a
142 * means to absolutely guarantee detection of all changes including some edge cases in some browsers which
143 * do not fire native events. Defaults to <tt>false</tt>.
146 <span id='Ext-form.Panel-cfg-pollInterval'> /**
147 </span> * @cfg {Number} pollInterval
148 * Interval in milliseconds at which the form's fields are checked for value changes. Only used if
149 * the {@link #pollForChanges} option is set to <tt>true</tt>. Defaults to 500 milliseconds.
152 <span id='Ext-form.Panel-cfg-layout'> /**
153 </span> * @cfg {String} layout The {@link Ext.container.Container#layout} for the form panel's immediate child items.
154 * Defaults to <tt>'anchor'</tt>.
160 initComponent: function() {
167 me.initFieldAncestor();
170 me.relayEvents(me.form, [
178 // Start polling if configured
179 if (me.pollForChanges) {
180 me.startPolling(me.pollInterval || 500);
184 initItems: function() {
185 // Create the BasicForm
188 me.form = me.createForm();
190 me.form.initialize();
193 <span id='Ext-form.Panel-method-createForm'> /**
196 createForm: function() {
197 return Ext.create('Ext.form.Basic', this, Ext.applyIf({listeners: {}}, this.initialConfig));
200 <span id='Ext-form.Panel-method-getForm'> /**
201 </span> * Provides access to the {@link Ext.form.Basic Form} which this Panel contains.
202 * @return {Ext.form.Basic} The {@link Ext.form.Basic Form} which this Panel contains.
204 getForm: function() {
208 <span id='Ext-form.Panel-method-loadRecord'> /**
209 </span> * Loads an {@link Ext.data.Model} into this form (internally just calls {@link Ext.form.Basic#loadRecord})
210 * See also {@link #trackResetOnLoad}.
211 * @param {Ext.data.Model} record The record to load
212 * @return {Ext.form.Basic} The Ext.form.Basic attached to this FormPanel
214 loadRecord: function(record) {
215 return this.getForm().loadRecord(record);
218 <span id='Ext-form.Panel-method-getRecord'> /**
219 </span> * Returns the currently loaded Ext.data.Model instance if one was loaded via {@link #loadRecord}.
220 * @return {Ext.data.Model} The loaded instance
222 getRecord: function() {
223 return this.getForm().getRecord();
226 <span id='Ext-form.Panel-method-getValues'> /**
227 </span> * Convenience function for fetching the current value of each field in the form. This is the same as calling
228 * {@link Ext.form.Basic#getValues this.getForm().getValues()}
229 * @return {Object} The current form field values, keyed by field name
231 getValues: function() {
232 return this.getForm().getValues();
235 beforeDestroy: function() {
241 <span id='Ext-form.Panel-method-load'> /**
242 </span> * This is a proxy for the underlying BasicForm's {@link Ext.form.Basic#load} call.
243 * @param {Object} options The options to pass to the action (see {@link Ext.form.Basic#load} and
244 * {@link Ext.form.Basic#doAction} for details)
246 load: function(options) {
247 this.form.load(options);
250 <span id='Ext-form.Panel-method-submit'> /**
251 </span> * This is a proxy for the underlying BasicForm's {@link Ext.form.Basic#submit} call.
252 * @param {Object} options The options to pass to the action (see {@link Ext.form.Basic#submit} and
253 * {@link Ext.form.Basic#doAction} for details)
255 submit: function(options) {
256 this.form.submit(options);
260 * Inherit docs, not using onDisable because it only gets fired
261 * when the component is rendered.
263 disable: function(silent) {
264 this.callParent(arguments);
265 this.form.getFields().each(function(field) {
271 * Inherit docs, not using onEnable because it only gets fired
272 * when the component is rendered.
274 enable: function(silent) {
275 this.callParent(arguments);
276 this.form.getFields().each(function(field) {
281 <span id='Ext-form.Panel-method-startPolling'> /**
282 </span> * Start an interval task to continuously poll all the fields in the form for changes in their
283 * values. This is normally started automatically by setting the {@link #pollForChanges} config.
284 * @param {Number} interval The interval in milliseconds at which the check should run.
286 startPolling: function(interval) {
288 var task = Ext.create('Ext.util.TaskRunner', interval);
291 run: this.checkChange,
294 this.pollTask = task;
297 <span id='Ext-form.Panel-method-stopPolling'> /**
298 </span> * Stop a running interval task that was started by {@link #startPolling}.
300 stopPolling: function() {
301 var task = this.pollTask;
304 delete this.pollTask;
308 <span id='Ext-form.Panel-method-checkChange'> /**
309 </span> * Forces each field within the form panel to
310 * {@link Ext.form.field.Field#checkChange check if its value has changed}.
312 checkChange: function() {
313 this.form.getFields().each(function(field) {
318 </pre></pre></body></html>