Upgrade to ExtJS 3.2.0 - Released 03/30/2010
[extjs.git] / docs / source / BasicForm.html
1 <html>
2 <head>
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>
7 </head>
8 <body  onload="prettyPrint();">
9     <pre class="prettyprint lang-js">/*!
10  * Ext JS Library 3.2.0
11  * Copyright(c) 2006-2010 Ext JS, Inc.
12  * licensing@extjs.com
13  * http://www.extjs.com/license
14  */
15 <div id="cls-Ext.form.BasicForm"></div>/**
16  * @class Ext.form.BasicForm
17  * @extends Ext.util.Observable
18  * <p>Encapsulates the DOM &lt;form> element at the heart of the {@link Ext.form.FormPanel FormPanel} class, and provides
19  * input field management, validation, submission, and form loading services.</p>
20  * <p>By default, Ext Forms are submitted through Ajax, using an instance of {@link Ext.form.Action.Submit}.
21  * To enable normal browser submission of an Ext Form, use the {@link #standardSubmit} config option.</p>
22  * <p><b><u>File Uploads</u></b></p>
23  * <p>{@link #fileUpload File uploads} are not performed using Ajax submission, that
24  * is they are <b>not</b> performed using XMLHttpRequests. Instead the form is submitted in the standard
25  * manner with the DOM <tt>&lt;form></tt> element temporarily modified to have its
26  * <a href="http://www.w3.org/TR/REC-html40/present/frames.html#adef-target">target</a> set to refer
27  * to a dynamically generated, hidden <tt>&lt;iframe></tt> which is inserted into the document
28  * but removed after the return data has been gathered.</p>
29  * <p>The server response is parsed by the browser to create the document for the IFRAME. If the
30  * server is using JSON to send the return object, then the
31  * <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17">Content-Type</a> header
32  * must be set to "text/html" in order to tell the browser to insert the text unchanged into the document body.</p>
33  * <p>Characters which are significant to an HTML parser must be sent as HTML entities, so encode
34  * "&lt;" as "&amp;lt;", "&amp;" as "&amp;amp;" etc.</p>
35  * <p>The response text is retrieved from the document, and a fake XMLHttpRequest object
36  * is created containing a <tt>responseText</tt> property in order to conform to the
37  * requirements of event handlers and callbacks.</p>
38  * <p>Be aware that file upload packets are sent with the content type <a href="http://www.faqs.org/rfcs/rfc2388.html">multipart/form</a>
39  * and some server technologies (notably JEE) may require some custom processing in order to
40  * retrieve parameter names and parameter values from the packet content.</p>
41  * @constructor
42  * @param {Mixed} el The form element or its id
43  * @param {Object} config Configuration options
44  */
45 Ext.form.BasicForm = Ext.extend(Ext.util.Observable, {
46
47     constructor: function(el, config){
48         Ext.apply(this, config);
49         if(Ext.isString(this.paramOrder)){
50             this.paramOrder = this.paramOrder.split(/[\s,|]/);
51         }
52         <div id="prop-Ext.form.BasicForm-items"></div>/**
53          * A {@link Ext.util.MixedCollection MixedCollection} containing all the Ext.form.Fields in this form.
54          * @type MixedCollection
55          * @property items
56          */
57         this.items = new Ext.util.MixedCollection(false, function(o){
58             return o.getItemId();
59         });
60         this.addEvents(
61             <div id="event-Ext.form.BasicForm-beforeaction"></div>/**
62              * @event beforeaction
63              * Fires before any action is performed. Return false to cancel the action.
64              * @param {Form} this
65              * @param {Action} action The {@link Ext.form.Action} to be performed
66              */
67             'beforeaction',
68             <div id="event-Ext.form.BasicForm-actionfailed"></div>/**
69              * @event actionfailed
70              * Fires when an action fails.
71              * @param {Form} this
72              * @param {Action} action The {@link Ext.form.Action} that failed
73              */
74             'actionfailed',
75             <div id="event-Ext.form.BasicForm-actioncomplete"></div>/**
76              * @event actioncomplete
77              * Fires when an action is completed.
78              * @param {Form} this
79              * @param {Action} action The {@link Ext.form.Action} that completed
80              */
81             'actioncomplete'
82         );
83
84         if(el){
85             this.initEl(el);
86         }
87         Ext.form.BasicForm.superclass.constructor.call(this);
88     },
89
90     <div id="cfg-Ext.form.BasicForm-method"></div>/**
91      * @cfg {String} method
92      * The request method to use (GET or POST) for form actions if one isn't supplied in the action options.
93      */
94     <div id="cfg-Ext.form.BasicForm-reader"></div>/**
95      * @cfg {DataReader} reader
96      * An Ext.data.DataReader (e.g. {@link Ext.data.XmlReader}) to be used to read
97      * data when executing 'load' actions. This is optional as there is built-in
98      * support for processing JSON.  For additional information on using an XMLReader
99      * see the example provided in examples/form/xml-form.html.
100      */
101     <div id="cfg-Ext.form.BasicForm-errorReader"></div>/**
102      * @cfg {DataReader} errorReader
103      * <p>An Ext.data.DataReader (e.g. {@link Ext.data.XmlReader}) to be used to
104      * read field error messages returned from 'submit' actions. This is optional
105      * as there is built-in support for processing JSON.</p>
106      * <p>The Records which provide messages for the invalid Fields must use the
107      * Field name (or id) as the Record ID, and must contain a field called 'msg'
108      * which contains the error message.</p>
109      * <p>The errorReader does not have to be a full-blown implementation of a
110      * DataReader. It simply needs to implement a <tt>read(xhr)</tt> function
111      * which returns an Array of Records in an object with the following
112      * structure:</p><pre><code>
113 {
114     records: recordArray
115 }
116 </code></pre>
117      */
118     <div id="cfg-Ext.form.BasicForm-url"></div>/**
119      * @cfg {String} url
120      * The URL to use for form actions if one isn't supplied in the
121      * <code>{@link #doAction doAction} options</code>.
122      */
123     <div id="cfg-Ext.form.BasicForm-fileUpload"></div>/**
124      * @cfg {Boolean} fileUpload
125      * Set to true if this form is a file upload.
126      * <p>File uploads are not performed using normal 'Ajax' techniques, that is they are <b>not</b>
127      * performed using XMLHttpRequests. Instead the form is submitted in the standard manner with the
128      * DOM <tt>&lt;form></tt> element temporarily modified to have its
129      * <a href="http://www.w3.org/TR/REC-html40/present/frames.html#adef-target">target</a> set to refer
130      * to a dynamically generated, hidden <tt>&lt;iframe></tt> which is inserted into the document
131      * but removed after the return data has been gathered.</p>
132      * <p>The server response is parsed by the browser to create the document for the IFRAME. If the
133      * server is using JSON to send the return object, then the
134      * <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17">Content-Type</a> header
135      * must be set to "text/html" in order to tell the browser to insert the text unchanged into the document body.</p>
136      * <p>Characters which are significant to an HTML parser must be sent as HTML entities, so encode
137      * "&lt;" as "&amp;lt;", "&amp;" as "&amp;amp;" etc.</p>
138      * <p>The response text is retrieved from the document, and a fake XMLHttpRequest object
139      * is created containing a <tt>responseText</tt> property in order to conform to the
140      * requirements of event handlers and callbacks.</p>
141      * <p>Be aware that file upload packets are sent with the content type <a href="http://www.faqs.org/rfcs/rfc2388.html">multipart/form</a>
142      * and some server technologies (notably JEE) may require some custom processing in order to
143      * retrieve parameter names and parameter values from the packet content.</p>
144      */
145     <div id="cfg-Ext.form.BasicForm-baseParams"></div>/**
146      * @cfg {Object} baseParams
147      * <p>Parameters to pass with all requests. e.g. baseParams: {id: '123', foo: 'bar'}.</p>
148      * <p>Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode}.</p>
149      */
150     <div id="cfg-Ext.form.BasicForm-timeout"></div>/**
151      * @cfg {Number} timeout Timeout for form actions in seconds (default is 30 seconds).
152      */
153     timeout: 30,
154
155     <div id="cfg-Ext.form.BasicForm-api"></div>/**
156      * @cfg {Object} api (Optional) If specified load and submit actions will be handled
157      * with {@link Ext.form.Action.DirectLoad} and {@link Ext.form.Action.DirectSubmit}.
158      * Methods which have been imported by Ext.Direct can be specified here to load and submit
159      * forms.
160      * Such as the following:<pre><code>
161 api: {
162     load: App.ss.MyProfile.load,
163     submit: App.ss.MyProfile.submit
164 }
165 </code></pre>
166      * <p>Load actions can use <code>{@link #paramOrder}</code> or <code>{@link #paramsAsHash}</code>
167      * to customize how the load method is invoked.
168      * Submit actions will always use a standard form submit. The formHandler configuration must
169      * be set on the associated server-side method which has been imported by Ext.Direct</p>
170      */
171
172     <div id="cfg-Ext.form.BasicForm-paramOrder"></div>/**
173      * @cfg {Array/String} paramOrder <p>A list of params to be executed server side.
174      * Defaults to <tt>undefined</tt>. Only used for the <code>{@link #api}</code>
175      * <code>load</code> configuration.</p>
176      * <br><p>Specify the params in the order in which they must be executed on the
177      * server-side as either (1) an Array of String values, or (2) a String of params
178      * delimited by either whitespace, comma, or pipe. For example,
179      * any of the following would be acceptable:</p><pre><code>
180 paramOrder: ['param1','param2','param3']
181 paramOrder: 'param1 param2 param3'
182 paramOrder: 'param1,param2,param3'
183 paramOrder: 'param1|param2|param'
184      </code></pre>
185      */
186     paramOrder: undefined,
187
188     <div id="cfg-Ext.form.BasicForm-paramsAsHash"></div>/**
189      * @cfg {Boolean} paramsAsHash Only used for the <code>{@link #api}</code>
190      * <code>load</code> configuration. Send parameters as a collection of named
191      * arguments (defaults to <tt>false</tt>). Providing a
192      * <tt>{@link #paramOrder}</tt> nullifies this configuration.
193      */
194     paramsAsHash: false,
195
196     <div id="cfg-Ext.form.BasicForm-waitTitle"></div>/**
197      * @cfg {String} waitTitle
198      * The default title to show for the waiting message box (defaults to <tt>'Please Wait...'</tt>)
199      */
200     waitTitle: 'Please Wait...',
201
202     // private
203     activeAction : null,
204
205     <div id="cfg-Ext.form.BasicForm-trackResetOnLoad"></div>/**
206      * @cfg {Boolean} trackResetOnLoad If set to <tt>true</tt>, {@link #reset}() resets to the last loaded
207      * or {@link #setValues}() data instead of when the form was first created.  Defaults to <tt>false</tt>.
208      */
209     trackResetOnLoad : false,
210
211     <div id="cfg-Ext.form.BasicForm-standardSubmit"></div>/**
212      * @cfg {Boolean} standardSubmit
213      * <p>If set to <tt>true</tt>, standard HTML form submits are used instead
214      * of XHR (Ajax) style form submissions. Defaults to <tt>false</tt>.</p>
215      * <br><p><b>Note:</b> When using <code>standardSubmit</code>, the
216      * <code>options</code> to <code>{@link #submit}</code> are ignored because
217      * Ext's Ajax infrastracture is bypassed. To pass extra parameters (e.g.
218      * <code>baseParams</code> and <code>params</code>), utilize hidden fields
219      * to submit extra data, for example:</p>
220      * <pre><code>
221 new Ext.FormPanel({
222     standardSubmit: true,
223     baseParams: {
224         foo: 'bar'
225     },
226     {@link url}: 'myProcess.php',
227     items: [{
228         xtype: 'textfield',
229         name: 'userName'
230     }],
231     buttons: [{
232         text: 'Save',
233         handler: function(){
234             var fp = this.ownerCt.ownerCt,
235                 form = fp.getForm();
236             if (form.isValid()) {
237                 // check if there are baseParams and if
238                 // hiddent items have been added already
239                 if (fp.baseParams && !fp.paramsAdded) {
240                     // add hidden items for all baseParams
241                     for (i in fp.baseParams) {
242                         fp.add({
243                             xtype: 'hidden',
244                             name: i,
245                             value: fp.baseParams[i]
246                         });
247                     }
248                     fp.doLayout();
249                     // set a custom flag to prevent re-adding
250                     fp.paramsAdded = true;
251                 }
252                 form.{@link #submit}();
253             }
254         }
255     }]
256 });
257      * </code></pre>
258      */
259     <div id="prop-Ext.form.BasicForm-waitMsgTarget"></div>/**
260      * By default wait messages are displayed with Ext.MessageBox.wait. You can target a specific
261      * element by passing it or its id or mask the form itself by passing in true.
262      * @type Mixed
263      * @property waitMsgTarget
264      */
265
266     // private
267     initEl : function(el){
268         this.el = Ext.get(el);
269         this.id = this.el.id || Ext.id();
270         if(!this.standardSubmit){
271             this.el.on('submit', this.onSubmit, this);
272         }
273         this.el.addClass('x-form');
274     },
275
276     <div id="method-Ext.form.BasicForm-getEl"></div>/**
277      * Get the HTML form Element
278      * @return Ext.Element
279      */
280     getEl: function(){
281         return this.el;
282     },
283
284     // private
285     onSubmit : function(e){
286         e.stopEvent();
287     },
288
289     /**
290      * Destroys this object.
291      * @private
292      * @param {Boolean} bound true if the object is bound to a form panel. If this is the case
293      * the FormPanel will take care of destroying certain things, so we're just doubling up.
294      */
295     destroy: function(bound){
296         if(bound !== true){
297             this.items.each(function(f){
298                 Ext.destroy(f);
299             });
300             Ext.destroy(this.el);
301         }
302         this.items.clear();
303         this.purgeListeners();
304     },
305
306     <div id="method-Ext.form.BasicForm-isValid"></div>/**
307      * Returns true if client-side validation on the form is successful.
308      * @return Boolean
309      */
310     isValid : function(){
311         var valid = true;
312         this.items.each(function(f){
313            if(!f.validate()){
314                valid = false;
315            }
316         });
317         return valid;
318     },
319
320     <div id="method-Ext.form.BasicForm-isDirty"></div>/**
321      * <p>Returns true if any fields in this form have changed from their original values.</p>
322      * <p>Note that if this BasicForm was configured with {@link #trackResetOnLoad} then the
323      * Fields' <i>original values</i> are updated when the values are loaded by {@link #setValues}
324      * or {@link #loadRecord}.</p>
325      * @return Boolean
326      */
327     isDirty : function(){
328         var dirty = false;
329         this.items.each(function(f){
330            if(f.isDirty()){
331                dirty = true;
332                return false;
333            }
334         });
335         return dirty;
336     },
337
338     <div id="method-Ext.form.BasicForm-doAction"></div>/**
339      * Performs a predefined action ({@link Ext.form.Action.Submit} or
340      * {@link Ext.form.Action.Load}) or a custom extension of {@link Ext.form.Action}
341      * to perform application-specific processing.
342      * @param {String/Object} actionName The name of the predefined action type,
343      * or instance of {@link Ext.form.Action} to perform.
344      * @param {Object} options (optional) The options to pass to the {@link Ext.form.Action}.
345      * All of the config options listed below are supported by both the
346      * {@link Ext.form.Action.Submit submit} and {@link Ext.form.Action.Load load}
347      * actions unless otherwise noted (custom actions could also accept
348      * other config options):<ul>
349      *
350      * <li><b>url</b> : String<div class="sub-desc">The url for the action (defaults
351      * to the form's {@link #url}.)</div></li>
352      *
353      * <li><b>method</b> : String<div class="sub-desc">The form method to use (defaults
354      * to the form's method, or POST if not defined)</div></li>
355      *
356      * <li><b>params</b> : String/Object<div class="sub-desc"><p>The params to pass
357      * (defaults to the form's baseParams, or none if not defined)</p>
358      * <p>Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode}.</p></div></li>
359      *
360      * <li><b>headers</b> : Object<div class="sub-desc">Request headers to set for the action
361      * (defaults to the form's default headers)</div></li>
362      *
363      * <li><b>success</b> : Function<div class="sub-desc">The callback that will
364      * be invoked after a successful response (see top of
365      * {@link Ext.form.Action.Submit submit} and {@link Ext.form.Action.Load load}
366      * for a description of what constitutes a successful response).
367      * The function is passed the following parameters:<ul>
368      * <li><tt>form</tt> : Ext.form.BasicForm<div class="sub-desc">The form that requested the action</div></li>
369      * <li><tt>action</tt> : The {@link Ext.form.Action Action} object which performed the operation.
370      * <div class="sub-desc">The action object contains these properties of interest:<ul>
371      * <li><tt>{@link Ext.form.Action#response response}</tt></li>
372      * <li><tt>{@link Ext.form.Action#result result}</tt> : interrogate for custom postprocessing</li>
373      * <li><tt>{@link Ext.form.Action#type type}</tt></li>
374      * </ul></div></li></ul></div></li>
375      *
376      * <li><b>failure</b> : Function<div class="sub-desc">The callback that will be invoked after a
377      * failed transaction attempt. The function is passed the following parameters:<ul>
378      * <li><tt>form</tt> : The {@link Ext.form.BasicForm} that requested the action.</li>
379      * <li><tt>action</tt> : The {@link Ext.form.Action Action} object which performed the operation.
380      * <div class="sub-desc">The action object contains these properties of interest:<ul>
381      * <li><tt>{@link Ext.form.Action#failureType failureType}</tt></li>
382      * <li><tt>{@link Ext.form.Action#response response}</tt></li>
383      * <li><tt>{@link Ext.form.Action#result result}</tt> : interrogate for custom postprocessing</li>
384      * <li><tt>{@link Ext.form.Action#type type}</tt></li>
385      * </ul></div></li></ul></div></li>
386      *
387      * <li><b>scope</b> : Object<div class="sub-desc">The scope in which to call the
388      * callback functions (The <tt>this</tt> reference for the callback functions).</div></li>
389      *
390      * <li><b>clientValidation</b> : Boolean<div class="sub-desc">Submit Action only.
391      * Determines whether a Form's fields are validated in a final call to
392      * {@link Ext.form.BasicForm#isValid isValid} prior to submission. Set to <tt>false</tt>
393      * to prevent this. If undefined, pre-submission field validation is performed.</div></li></ul>
394      *
395      * @return {BasicForm} this
396      */
397     doAction : function(action, options){
398         if(Ext.isString(action)){
399             action = new Ext.form.Action.ACTION_TYPES[action](this, options);
400         }
401         if(this.fireEvent('beforeaction', this, action) !== false){
402             this.beforeAction(action);
403             action.run.defer(100, action);
404         }
405         return this;
406     },
407
408     <div id="method-Ext.form.BasicForm-submit"></div>/**
409      * Shortcut to {@link #doAction do} a {@link Ext.form.Action.Submit submit action}.
410      * @param {Object} options The options to pass to the action (see {@link #doAction} for details).<br>
411      * <p><b>Note:</b> this is ignored when using the {@link #standardSubmit} option.</p>
412      * <p>The following code:</p><pre><code>
413 myFormPanel.getForm().submit({
414     clientValidation: true,
415     url: 'updateConsignment.php',
416     params: {
417         newStatus: 'delivered'
418     },
419     success: function(form, action) {
420        Ext.Msg.alert('Success', action.result.msg);
421     },
422     failure: function(form, action) {
423         switch (action.failureType) {
424             case Ext.form.Action.CLIENT_INVALID:
425                 Ext.Msg.alert('Failure', 'Form fields may not be submitted with invalid values');
426                 break;
427             case Ext.form.Action.CONNECT_FAILURE:
428                 Ext.Msg.alert('Failure', 'Ajax communication failed');
429                 break;
430             case Ext.form.Action.SERVER_INVALID:
431                Ext.Msg.alert('Failure', action.result.msg);
432        }
433     }
434 });
435 </code></pre>
436      * would process the following server response for a successful submission:<pre><code>
437 {
438     "success":true, // note this is Boolean, not string
439     "msg":"Consignment updated"
440 }
441 </code></pre>
442      * and the following server response for a failed submission:<pre><code>
443 {
444     "success":false, // note this is Boolean, not string
445     "msg":"You do not have permission to perform this operation"
446 }
447 </code></pre>
448      * @return {BasicForm} this
449      */
450     submit : function(options){
451         options = options || {};
452         if(this.standardSubmit){
453             var v = options.clientValidation === false || this.isValid();
454             if(v){
455                 var el = this.el.dom;
456                 if(this.url && Ext.isEmpty(el.action)){
457                     el.action = this.url;
458                 }
459                 el.submit();
460             }
461             return v;
462         }
463         var submitAction = String.format('{0}submit', this.api ? 'direct' : '');
464         this.doAction(submitAction, options);
465         return this;
466     },
467
468     <div id="method-Ext.form.BasicForm-load"></div>/**
469      * Shortcut to {@link #doAction do} a {@link Ext.form.Action.Load load action}.
470      * @param {Object} options The options to pass to the action (see {@link #doAction} for details)
471      * @return {BasicForm} this
472      */
473     load : function(options){
474         var loadAction = String.format('{0}load', this.api ? 'direct' : '');
475         this.doAction(loadAction, options);
476         return this;
477     },
478
479     <div id="method-Ext.form.BasicForm-updateRecord"></div>/**
480      * Persists the values in this form into the passed {@link Ext.data.Record} object in a beginEdit/endEdit block.
481      * @param {Record} record The record to edit
482      * @return {BasicForm} this
483      */
484     updateRecord : function(record){
485         record.beginEdit();
486         var fs = record.fields;
487         fs.each(function(f){
488             var field = this.findField(f.name);
489             if(field){
490                 record.set(f.name, field.getValue());
491             }
492         }, this);
493         record.endEdit();
494         return this;
495     },
496
497     <div id="method-Ext.form.BasicForm-loadRecord"></div>/**
498      * Loads an {@link Ext.data.Record} into this form by calling {@link #setValues} with the
499      * {@link Ext.data.Record#data record data}.
500      * See also {@link #trackResetOnLoad}.
501      * @param {Record} record The record to load
502      * @return {BasicForm} this
503      */
504     loadRecord : function(record){
505         this.setValues(record.data);
506         return this;
507     },
508
509     // private
510     beforeAction : function(action){
511         // Call HtmlEditor's syncValue before actions
512         this.items.each(function(f){
513             if(f.isFormField && f.syncValue){
514                 f.syncValue();
515             }
516         });
517         var o = action.options;
518         if(o.waitMsg){
519             if(this.waitMsgTarget === true){
520                 this.el.mask(o.waitMsg, 'x-mask-loading');
521             }else if(this.waitMsgTarget){
522                 this.waitMsgTarget = Ext.get(this.waitMsgTarget);
523                 this.waitMsgTarget.mask(o.waitMsg, 'x-mask-loading');
524             }else{
525                 Ext.MessageBox.wait(o.waitMsg, o.waitTitle || this.waitTitle);
526             }
527         }
528     },
529
530     // private
531     afterAction : function(action, success){
532         this.activeAction = null;
533         var o = action.options;
534         if(o.waitMsg){
535             if(this.waitMsgTarget === true){
536                 this.el.unmask();
537             }else if(this.waitMsgTarget){
538                 this.waitMsgTarget.unmask();
539             }else{
540                 Ext.MessageBox.updateProgress(1);
541                 Ext.MessageBox.hide();
542             }
543         }
544         if(success){
545             if(o.reset){
546                 this.reset();
547             }
548             Ext.callback(o.success, o.scope, [this, action]);
549             this.fireEvent('actioncomplete', this, action);
550         }else{
551             Ext.callback(o.failure, o.scope, [this, action]);
552             this.fireEvent('actionfailed', this, action);
553         }
554     },
555
556     <div id="method-Ext.form.BasicForm-findField"></div>/**
557      * Find a {@link Ext.form.Field} in this form.
558      * @param {String} id The value to search for (specify either a {@link Ext.Component#id id},
559      * {@link Ext.grid.Column#dataIndex dataIndex}, {@link Ext.form.Field#getName name or hiddenName}).
560      * @return Field
561      */
562     findField : function(id) {
563         var field = this.items.get(id);
564
565         if (!Ext.isObject(field)) {
566             //searches for the field corresponding to the given id. Used recursively for composite fields
567             var findMatchingField = function(f) {
568                 if (f.isFormField) {
569                     if (f.dataIndex == id || f.id == id || f.getName() == id) {
570                         field = f;
571                         return false;
572                     } else if (f.isComposite) {
573                         return f.items.each(findMatchingField);
574                     }
575                 }
576             };
577
578             this.items.each(findMatchingField);
579         }
580         return field || null;
581     },
582
583
584     <div id="method-Ext.form.BasicForm-markInvalid"></div>/**
585      * Mark fields in this form invalid in bulk.
586      * @param {Array/Object} errors Either an array in the form [{id:'fieldId', msg:'The message'},...] or an object hash of {id: msg, id2: msg2}
587      * @return {BasicForm} this
588      */
589     markInvalid : function(errors){
590         if (Ext.isArray(errors)) {
591             for(var i = 0, len = errors.length; i < len; i++){
592                 var fieldError = errors[i];
593                 var f = this.findField(fieldError.id);
594                 if(f){
595                     f.markInvalid(fieldError.msg);
596                 }
597             }
598         } else {
599             var field, id;
600             for(id in errors){
601                 if(!Ext.isFunction(errors[id]) && (field = this.findField(id))){
602                     field.markInvalid(errors[id]);
603                 }
604             }
605         }
606
607         return this;
608     },
609
610     <div id="method-Ext.form.BasicForm-setValues"></div>/**
611      * Set values for fields in this form in bulk.
612      * @param {Array/Object} values Either an array in the form:<pre><code>
613 [{id:'clientName', value:'Fred. Olsen Lines'},
614  {id:'portOfLoading', value:'FXT'},
615  {id:'portOfDischarge', value:'OSL'} ]</code></pre>
616      * or an object hash of the form:<pre><code>
617 {
618     clientName: 'Fred. Olsen Lines',
619     portOfLoading: 'FXT',
620     portOfDischarge: 'OSL'
621 }</code></pre>
622      * @return {BasicForm} this
623      */
624     setValues : function(values){
625         if(Ext.isArray(values)){ // array of objects
626             for(var i = 0, len = values.length; i < len; i++){
627                 var v = values[i];
628                 var f = this.findField(v.id);
629                 if(f){
630                     f.setValue(v.value);
631                     if(this.trackResetOnLoad){
632                         f.originalValue = f.getValue();
633                     }
634                 }
635             }
636         }else{ // object hash
637             var field, id;
638             for(id in values){
639                 if(!Ext.isFunction(values[id]) && (field = this.findField(id))){
640                     field.setValue(values[id]);
641                     if(this.trackResetOnLoad){
642                         field.originalValue = field.getValue();
643                     }
644                 }
645             }
646         }
647         return this;
648     },
649
650     <div id="method-Ext.form.BasicForm-getValues"></div>/**
651      * <p>Returns the fields in this form as an object with key/value pairs as they would be submitted using a standard form submit.
652      * If multiple fields exist with the same name they are returned as an array.</p>
653      * <p><b>Note:</b> The values are collected from all enabled HTML input elements within the form, <u>not</u> from
654      * the Ext Field objects. This means that all returned values are Strings (or Arrays of Strings) and that the
655      * value can potentially be the emptyText of a field.</p>
656      * @param {Boolean} asString (optional) Pass true to return the values as a string. (defaults to false, returning an Object)
657      * @return {String/Object}
658      */
659     getValues : function(asString){
660         var fs = Ext.lib.Ajax.serializeForm(this.el.dom);
661         if(asString === true){
662             return fs;
663         }
664         return Ext.urlDecode(fs);
665     },
666
667     <div id="method-Ext.form.BasicForm-getFieldValues"></div>/**
668      * Retrieves the fields in the form as a set of key/value pairs, using the {@link Ext.form.Field#getValue getValue()} method.
669      * If multiple fields exist with the same name they are returned as an array.
670      * @param {Boolean} dirtyOnly (optional) True to return only fields that are dirty.
671      * @return {Object} The values in the form
672      */
673     getFieldValues : function(dirtyOnly){
674         var o = {},
675             n,
676             key,
677             val;
678         this.items.each(function(f) {
679             if (dirtyOnly !== true || f.isDirty()) {
680                 n = f.getName();
681                 key = o[n];
682                 val = f.getValue();
683
684                 if(Ext.isDefined(key)){
685                     if(Ext.isArray(key)){
686                         o[n].push(val);
687                     }else{
688                         o[n] = [key, val];
689                     }
690                 }else{
691                     o[n] = val;
692                 }
693             }
694         });
695         return o;
696     },
697
698     <div id="method-Ext.form.BasicForm-clearInvalid"></div>/**
699      * Clears all invalid messages in this form.
700      * @return {BasicForm} this
701      */
702     clearInvalid : function(){
703         this.items.each(function(f){
704            f.clearInvalid();
705         });
706         return this;
707     },
708
709     <div id="method-Ext.form.BasicForm-reset"></div>/**
710      * Resets this form.
711      * @return {BasicForm} this
712      */
713     reset : function(){
714         this.items.each(function(f){
715             f.reset();
716         });
717         return this;
718     },
719
720     <div id="method-Ext.form.BasicForm-add"></div>/**
721      * Add Ext.form Components to this form's Collection. This does not result in rendering of
722      * the passed Component, it just enables the form to validate Fields, and distribute values to
723      * Fields.
724      * <p><b>You will not usually call this function. In order to be rendered, a Field must be added
725      * to a {@link Ext.Container Container}, usually an {@link Ext.form.FormPanel FormPanel}.
726      * The FormPanel to which the field is added takes care of adding the Field to the BasicForm's
727      * collection.</b></p>
728      * @param {Field} field1
729      * @param {Field} field2 (optional)
730      * @param {Field} etc (optional)
731      * @return {BasicForm} this
732      */
733     add : function(){
734         this.items.addAll(Array.prototype.slice.call(arguments, 0));
735         return this;
736     },
737
738     <div id="method-Ext.form.BasicForm-remove"></div>/**
739      * Removes a field from the items collection (does NOT remove its markup).
740      * @param {Field} field
741      * @return {BasicForm} this
742      */
743     remove : function(field){
744         this.items.remove(field);
745         return this;
746     },
747
748     <div id="method-Ext.form.BasicForm-render"></div>/**
749      * Iterates through the {@link Ext.form.Field Field}s which have been {@link #add add}ed to this BasicForm,
750      * checks them for an id attribute, and calls {@link Ext.form.Field#applyToMarkup} on the existing dom element with that id.
751      * @return {BasicForm} this
752      */
753     render : function(){
754         this.items.each(function(f){
755             if(f.isFormField && !f.rendered && document.getElementById(f.id)){ // if the element exists
756                 f.applyToMarkup(f.id);
757             }
758         });
759         return this;
760     },
761
762     <div id="method-Ext.form.BasicForm-applyToFields"></div>/**
763      * Calls {@link Ext#apply} for all fields in this form with the passed object.
764      * @param {Object} values
765      * @return {BasicForm} this
766      */
767     applyToFields : function(o){
768         this.items.each(function(f){
769            Ext.apply(f, o);
770         });
771         return this;
772     },
773
774     <div id="method-Ext.form.BasicForm-applyIfToFields"></div>/**
775      * Calls {@link Ext#applyIf} for all field in this form with the passed object.
776      * @param {Object} values
777      * @return {BasicForm} this
778      */
779     applyIfToFields : function(o){
780         this.items.each(function(f){
781            Ext.applyIf(f, o);
782         });
783         return this;
784     },
785
786     callFieldMethod : function(fnName, args){
787         args = args || [];
788         this.items.each(function(f){
789             if(Ext.isFunction(f[fnName])){
790                 f[fnName].apply(f, args);
791             }
792         });
793         return this;
794     }
795 });
796
797 // back compat
798 Ext.BasicForm = Ext.form.BasicForm;
799 </pre>    
800 </body>
801 </html>