3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.com/license
15 <div id="cls-Ext.form.FormPanel"></div>/**
16 * @class Ext.form.FormPanel
18 * <p>Standard form container.</p>
20 * <p><b><u>Layout</u></b></p>
21 * <p>By default, FormPanel is configured with <tt>layout:'form'</tt> to use an {@link Ext.layout.FormLayout}
22 * layout manager, which styles and renders fields and labels correctly. When nesting additional Containers
23 * within a FormPanel, you should ensure that any descendant Containers which host input Fields use the
24 * {@link Ext.layout.FormLayout} layout manager.</p>
26 * <p><b><u>BasicForm</u></b></p>
27 * <p>Although <b>not listed</b> as configuration options of FormPanel, the FormPanel class accepts all
28 * of the config options required to configure its internal {@link Ext.form.BasicForm} for:
29 * <div class="mdetail-params"><ul>
30 * <li>{@link Ext.form.BasicForm#fileUpload file uploads}</li>
31 * <li>functionality for {@link Ext.form.BasicForm#doAction loading, validating and submitting} the form</li>
34 * <p><b>Note</b>: If subclassing FormPanel, any configuration options for the BasicForm must be applied to
35 * the <tt><b>initialConfig</b></tt> property of the FormPanel. Applying {@link Ext.form.BasicForm BasicForm}
36 * configuration settings to <b><tt>this</tt></b> will <b>not</b> affect the BasicForm's configuration.</p>
38 * <p><b><u>Form Validation</u></b></p>
39 * <p>For information on form validation see the following:</p>
40 * <div class="mdetail-params"><ul>
41 * <li>{@link Ext.form.TextField}</li>
42 * <li>{@link Ext.form.VTypes}</li>
43 * <li>{@link Ext.form.BasicForm#doAction BasicForm.doAction <b>clientValidation</b> notes}</li>
44 * <li><tt>{@link Ext.form.FormPanel#monitorValid monitorValid}</tt></li>
47 * <p><b><u>Form Submission</u></b></p>
48 * <p>By default, Ext Forms are submitted through Ajax, using {@link Ext.form.Action}. To enable normal browser
49 * submission of the {@link Ext.form.BasicForm BasicForm} contained in this FormPanel, see the
50 * <tt><b>{@link Ext.form.BasicForm#standardSubmit standardSubmit}</b></tt> option.</p>
53 * @param {Object} config Configuration options
56 Ext.FormPanel = Ext.extend(Ext.Panel, {
57 <div id="cfg-Ext.form.FormPanel-formId"></div>/**
58 * @cfg {String} formId (optional) The id of the FORM tag (defaults to an auto-generated id).
60 <div id="cfg-Ext.form.FormPanel-hideLabels"></div>/**
61 * @cfg {Boolean} hideLabels
62 * <p><tt>true</tt> to hide field labels by default (sets <tt>display:none</tt>). Defaults to
64 * <p>Also see {@link Ext.Component}.<tt>{@link Ext.Component#hideLabel hideLabel}</tt>.
66 <div id="cfg-Ext.form.FormPanel-labelPad"></div>/**
67 * @cfg {Number} labelPad
68 * The default padding in pixels for field labels (defaults to <tt>5</tt>). <tt>labelPad</tt> only
69 * applies if <tt>{@link #labelWidth}</tt> is also specified, otherwise it will be ignored.
71 <div id="cfg-Ext.form.FormPanel-labelSeparator"></div>/**
72 * @cfg {String} labelSeparator
73 * See {@link Ext.Component}.<tt>{@link Ext.Component#labelSeparator labelSeparator}</tt>
75 <div id="cfg-Ext.form.FormPanel-labelWidth"></div>/**
76 * @cfg {Number} labelWidth The width of labels in pixels. This property cascades to child containers
77 * and can be overridden on any child container (e.g., a fieldset can specify a different <tt>labelWidth</tt>
78 * for its fields) (defaults to <tt>100</tt>).
80 <div id="cfg-Ext.form.FormPanel-itemCls"></div>/**
81 * @cfg {String} itemCls A css class to apply to the x-form-item of fields. This property cascades to child containers.
83 <div id="cfg-Ext.form.FormPanel-buttons"></div>/**
84 * @cfg {Array} buttons
85 * An array of {@link Ext.Button}s or {@link Ext.Button} configs used to add buttons to the footer of this FormPanel.<br>
86 * <p>Buttons in the footer of a FormPanel may be configured with the option <tt>formBind: true</tt>. This causes
87 * the form's {@link #monitorValid valid state monitor task} to enable/disable those Buttons depending on
88 * the form's valid/invalid state.</p>
92 <div id="cfg-Ext.form.FormPanel-minButtonWidth"></div>/**
93 * @cfg {Number} minButtonWidth Minimum width of all buttons in pixels (defaults to <tt>75</tt>).
97 <div id="cfg-Ext.form.FormPanel-labelAlign"></div>/**
98 * @cfg {String} labelAlign The label alignment value used for the <tt>text-align</tt> specification
99 * for the <b>container</b>. Valid values are <tt>"left</tt>", <tt>"top"</tt> or <tt>"right"</tt>
100 * (defaults to <tt>"left"</tt>). This property cascades to child <b>containers</b> and can be
101 * overridden on any child <b>container</b> (e.g., a fieldset can specify a different <tt>labelAlign</tt>
106 <div id="cfg-Ext.form.FormPanel-monitorValid"></div>/**
107 * @cfg {Boolean} monitorValid If <tt>true</tt>, the form monitors its valid state <b>client-side</b> and
108 * regularly fires the {@link #clientvalidation} event passing that state.<br>
109 * <p>When monitoring valid state, the FormPanel enables/disables any of its configured
110 * {@link #buttons} which have been configured with <code>formBind: true</code> depending
111 * on whether the {@link Ext.form.BasicForm#isValid form is valid} or not. Defaults to <tt>false</tt></p>
113 monitorValid : false,
115 <div id="cfg-Ext.form.FormPanel-monitorPoll"></div>/**
116 * @cfg {Number} monitorPoll The milliseconds to poll valid state, ignored if monitorValid is not true (defaults to 200)
120 <div id="cfg-Ext.form.FormPanel-layout"></div>/**
121 * @cfg {String} layout Defaults to <tt>'form'</tt>. Normally this configuration property should not be altered.
122 * For additional details see {@link Ext.layout.FormLayout} and {@link Ext.Container#layout Ext.Container.layout}.
127 initComponent : function(){
128 this.form = this.createForm();
129 Ext.FormPanel.superclass.initComponent.call(this);
133 cls: this.baseCls + '-body',
134 method : this.method || 'POST',
135 id : this.formId || Ext.id()
137 if(this.fileUpload) {
138 this.bodyCfg.enctype = 'multipart/form-data';
143 <div id="event-Ext.form.FormPanel-clientvalidation"></div>/**
144 * @event clientvalidation
145 * If the monitorValid config option is true, this event fires repetitively to notify of valid state
146 * @param {Ext.form.FormPanel} this
147 * @param {Boolean} valid true if the form has passed client-side validation
152 this.relayEvents(this.form, ['beforeaction', 'actionfailed', 'actioncomplete']);
156 createForm : function(){
157 var config = Ext.applyIf({listeners: {}}, this.initialConfig);
158 return new Ext.form.BasicForm(null, config);
162 initFields : function(){
164 var formPanel = this;
165 var fn = function(c){
166 if(formPanel.isField(c)){
168 }else if(c.findBy && c != formPanel){
169 formPanel.applySettings(c);
170 //each check required for check/radio groups.
171 if(c.items && c.items.each){
172 c.items.each(fn, this);
176 this.items.each(fn, this);
180 applySettings: function(c){
183 labelAlign: ct.labelAlign,
184 labelWidth: ct.labelWidth,
190 getLayoutTarget : function(){
194 <div id="method-Ext.form.FormPanel-getForm"></div>/**
195 * Provides access to the {@link Ext.form.BasicForm Form} which this Panel contains.
196 * @return {Ext.form.BasicForm} The {@link Ext.form.BasicForm Form} which this Panel contains.
198 getForm : function(){
203 onRender : function(ct, position){
205 Ext.FormPanel.superclass.onRender.call(this, ct, position);
206 this.form.initEl(this.body);
210 beforeDestroy : function(){
211 this.stopMonitoring();
212 this.form.destroy(true);
213 Ext.FormPanel.superclass.beforeDestroy.call(this);
216 // Determine if a Component is usable as a form Field.
217 isField : function(c) {
218 return !!c.setValue && !!c.getValue && !!c.markInvalid && !!c.clearInvalid;
222 initEvents : function(){
223 Ext.FormPanel.superclass.initEvents.call(this);
224 // Listeners are required here to catch bubbling events from children.
227 add: this.onAddEvent,
228 remove: this.onRemoveEvent
230 if(this.monitorValid){ // initialize after render
231 this.startMonitoring();
237 Ext.FormPanel.superclass.onAdd.call(this, c);
242 onAddEvent: function(ct, c){
249 processAdd : function(c){
250 // If a single form Field, add it
253 // If a Container, add any Fields it might contain
255 this.applySettings(c);
256 this.form.add.apply(this.form, c.findBy(this.isField));
261 onRemove: function(c){
262 Ext.FormPanel.superclass.onRemove.call(this, c);
263 this.processRemove(c);
266 onRemoveEvent: function(ct, c){
268 this.processRemove(c);
273 processRemove: function(c){
274 if(!this.destroying){
275 // If a single form Field, remove it
278 // If a Container, its already destroyed by the time it gets here. Remove any references to destroyed fields.
280 Ext.each(c.findBy(this.isField), this.form.remove, this.form);
282 * This isn't the most efficient way of getting rid of the items, however it's the most
283 * correct, which in this case is most important.
285 this.form.cleanDestroyed();
290 <div id="method-Ext.form.FormPanel-startMonitoring"></div>/**
291 * Starts monitoring of the valid state of this form. Usually this is done by passing the config
292 * option "monitorValid"
294 startMonitoring : function(){
296 this.validTask = new Ext.util.TaskRunner();
297 this.validTask.start({
298 run : this.bindHandler,
299 interval : this.monitorPoll || 200,
305 <div id="method-Ext.form.FormPanel-stopMonitoring"></div>/**
306 * Stops monitoring of the valid state of this form
308 stopMonitoring : function(){
310 this.validTask.stopAll();
311 this.validTask = null;
315 <div id="method-Ext.form.FormPanel-load"></div>/**
316 * This is a proxy for the underlying BasicForm's {@link Ext.form.BasicForm#load} call.
317 * @param {Object} options The options to pass to the action (see {@link Ext.form.BasicForm#doAction} for details)
320 this.form.load.apply(this.form, arguments);
324 onDisable : function(){
325 Ext.FormPanel.superclass.onDisable.call(this);
327 this.form.items.each(function(){
334 onEnable : function(){
335 Ext.FormPanel.superclass.onEnable.call(this);
337 this.form.items.each(function(){
344 bindHandler : function(){
346 this.form.items.each(function(f){
347 if(!f.isValid(true)){
353 var fitems = this.fbar.items.items;
354 for(var i = 0, len = fitems.length; i < len; i++){
356 if(btn.formBind === true && btn.disabled === valid){
357 btn.setDisabled(!valid);
361 this.fireEvent('clientvalidation', this, valid);
364 Ext.reg('form', Ext.FormPanel);
366 Ext.form.FormPanel = Ext.FormPanel;