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.Basic-method-constructor'><span id='Ext-form.Basic'>/**
2 </span></span> * @class Ext.form.Basic
3 * @extends Ext.util.Observable
5 Provides input field management, validation, submission, and form loading services for the collection
6 of {@link Ext.form.field.Field Field} instances within a {@link Ext.container.Container}. It is recommended
7 that you use a {@link Ext.form.Panel} as the form container, as that has logic to automatically
8 hook up an instance of {@link Ext.form.Basic} (plus other conveniences related to field configuration.)
12 The Basic class delegates the handling of form loads and submits to instances of {@link Ext.form.action.Action}.
13 See the various Action implementations for specific details of each one's functionality, as well as the
14 documentation for {@link #doAction} which details the configuration options that can be specified in
17 The default submit Action is {@link Ext.form.action.Submit}, which uses an Ajax request to submit the
18 form's values to a configured URL. To enable normal browser submission of an Ext form, use the
19 {@link #standardSubmit} config option.
21 Note: File uploads are not performed using normal 'Ajax' techniques; see the description for
22 {@link #hasUpload} for details.
26 Ext.create('Ext.form.Panel', {
28 renderTo: Ext.getBody(),
32 // Any configuration items here will be automatically passed along to
33 // the Ext.form.Basic instance when it gets created.
35 // The form will submit an AJAX request to this URL when submitted
46 // The getForm() method returns the Ext.form.Basic instance:
47 var form = this.up('form').getForm();
49 // Submit the Ajax request and handle the response
51 success: function(form, action) {
52 Ext.Msg.alert('Success', action.result.msg);
54 failure: function(form, action) {
55 Ext.Msg.alert('Failed', action.result.msg);
64 * @param {Ext.container.Container} owner The component that is the container for the form, usually a {@link Ext.form.Panel}
65 * @param {Object} config Configuration options. These are normally specified in the config to the
66 * {@link Ext.form.Panel} constructor, which passes them along to the BasicForm automatically.
69 * @docauthor Jason Johnston <jason@sencha.com>
74 Ext.define('Ext.form.Basic', {
75 extend: 'Ext.util.Observable',
76 alternateClassName: 'Ext.form.BasicForm',
77 requires: ['Ext.util.MixedCollection', 'Ext.form.action.Load', 'Ext.form.action.Submit',
78 'Ext.window.MessageBox', 'Ext.data.Errors'],
80 constructor: function(owner, config) {
82 onItemAddOrRemove = me.onItemAddOrRemove;
84 <span id='Ext-form.Basic-property-owner'> /**
85 </span> * @property owner
86 * @type Ext.container.Container
87 * The container component to which this BasicForm is attached.
91 // Listen for addition/removal of fields in the owner container
93 add: onItemAddOrRemove,
94 remove: onItemAddOrRemove,
98 Ext.apply(me, config);
100 // Normalize the paramOrder to an Array
101 if (Ext.isString(me.paramOrder)) {
102 me.paramOrder = me.paramOrder.split(/[\s,|]/);
106 <span id='Ext-form.Basic-event-beforeaction'> /**
107 </span> * @event beforeaction
108 * Fires before any action is performed. Return false to cancel the action.
109 * @param {Ext.form.Basic} this
110 * @param {Ext.form.action.Action} action The {@link Ext.form.action.Action} to be performed
113 <span id='Ext-form.Basic-event-actionfailed'> /**
114 </span> * @event actionfailed
115 * Fires when an action fails.
116 * @param {Ext.form.Basic} this
117 * @param {Ext.form.action.Action} action The {@link Ext.form.action.Action} that failed
120 <span id='Ext-form.Basic-event-actioncomplete'> /**
121 </span> * @event actioncomplete
122 * Fires when an action is completed.
123 * @param {Ext.form.Basic} this
124 * @param {Ext.form.action.Action} action The {@link Ext.form.action.Action} that completed
127 <span id='Ext-form.Basic-event-validitychange'> /**
128 </span> * @event validitychange
129 * Fires when the validity of the entire form changes.
130 * @param {Ext.form.Basic} this
131 * @param {Boolean} valid <tt>true</tt> if the form is now valid, <tt>false</tt> if it is now invalid.
134 <span id='Ext-form.Basic-event-dirtychange'> /**
135 </span> * @event dirtychange
136 * Fires when the dirty state of the entire form changes.
137 * @param {Ext.form.Basic} this
138 * @param {Boolean} dirty <tt>true</tt> if the form is now dirty, <tt>false</tt> if it is no longer dirty.
145 <span id='Ext-form.Basic-method-initialize'> /**
146 </span> * Do any post constructor initialization
149 initialize: function(){
150 this.initialized = true;
151 this.onValidityChange(!this.hasInvalidField());
154 <span id='Ext-form.Basic-cfg-method'> /**
155 </span> * @cfg {String} method
156 * The request method to use (GET or POST) for form actions if one isn't supplied in the action options.
158 <span id='Ext-form.Basic-cfg-reader'> /**
159 </span> * @cfg {Ext.data.reader.Reader} reader
160 * An Ext.data.DataReader (e.g. {@link Ext.data.reader.Xml}) to be used to read
161 * data when executing 'load' actions. This is optional as there is built-in
162 * support for processing JSON responses.
164 <span id='Ext-form.Basic-cfg-errorReader'> /**
165 </span> * @cfg {Ext.data.reader.Reader} errorReader
166 * <p>An Ext.data.DataReader (e.g. {@link Ext.data.reader.Xml}) to be used to
167 * read field error messages returned from 'submit' actions. This is optional
168 * as there is built-in support for processing JSON responses.</p>
169 * <p>The Records which provide messages for the invalid Fields must use the
170 * Field name (or id) as the Record ID, and must contain a field called 'msg'
171 * which contains the error message.</p>
172 * <p>The errorReader does not have to be a full-blown implementation of a
173 * Reader. It simply needs to implement a <tt>read(xhr)</tt> function
174 * which returns an Array of Records in an object with the following
175 * structure:</p><pre><code>
179 </code></pre>
182 <span id='Ext-form.Basic-cfg-url'> /**
183 </span> * @cfg {String} url
184 * The URL to use for form actions if one isn't supplied in the
185 * {@link #doAction doAction} options.
188 <span id='Ext-form.Basic-cfg-baseParams'> /**
189 </span> * @cfg {Object} baseParams
190 * <p>Parameters to pass with all requests. e.g. baseParams: {id: '123', foo: 'bar'}.</p>
191 * <p>Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode Ext.Object.toQueryString}.</p>
194 <span id='Ext-form.Basic-cfg-timeout'> /**
195 </span> * @cfg {Number} timeout Timeout for form actions in seconds (default is 30 seconds).
199 <span id='Ext-form.Basic-cfg-api'> /**
200 </span> * @cfg {Object} api (Optional) If specified, load and submit actions will be handled
201 * with {@link Ext.form.action.DirectLoad} and {@link Ext.form.action.DirectLoad}.
202 * Methods which have been imported by {@link Ext.direct.Manager} can be specified here to load and submit
204 * Such as the following:<pre><code>
206 load: App.ss.MyProfile.load,
207 submit: App.ss.MyProfile.submit
209 </code></pre>
210 * <p>Load actions can use <code>{@link #paramOrder}</code> or <code>{@link #paramsAsHash}</code>
211 * to customize how the load method is invoked.
212 * Submit actions will always use a standard form submit. The <tt>formHandler</tt> configuration must
213 * be set on the associated server-side method which has been imported by {@link Ext.direct.Manager}.</p>
216 <span id='Ext-form.Basic-cfg-paramOrder'> /**
217 </span> * @cfg {Array/String} paramOrder <p>A list of params to be executed server side.
218 * Defaults to <tt>undefined</tt>. Only used for the <code>{@link #api}</code>
219 * <code>load</code> configuration.</p>
220 * <p>Specify the params in the order in which they must be executed on the
221 * server-side as either (1) an Array of String values, or (2) a String of params
222 * delimited by either whitespace, comma, or pipe. For example,
223 * any of the following would be acceptable:</p><pre><code>
224 paramOrder: ['param1','param2','param3']
225 paramOrder: 'param1 param2 param3'
226 paramOrder: 'param1,param2,param3'
227 paramOrder: 'param1|param2|param'
228 </code></pre>
231 <span id='Ext-form.Basic-cfg-paramsAsHash'> /**
232 </span> * @cfg {Boolean} paramsAsHash Only used for the <code>{@link #api}</code>
233 * <code>load</code> configuration. If <tt>true</tt>, parameters will be sent as a
234 * single hash collection of named arguments (defaults to <tt>false</tt>). Providing a
235 * <tt>{@link #paramOrder}</tt> nullifies this configuration.
239 <span id='Ext-form.Basic-cfg-waitTitle'> /**
240 </span> * @cfg {String} waitTitle
241 * The default title to show for the waiting message box (defaults to <tt>'Please Wait...'</tt>)
243 waitTitle: 'Please Wait...',
245 <span id='Ext-form.Basic-cfg-trackResetOnLoad'> /**
246 </span> * @cfg {Boolean} trackResetOnLoad If set to <tt>true</tt>, {@link #reset}() resets to the last loaded
247 * or {@link #setValues}() data instead of when the form was first created. Defaults to <tt>false</tt>.
249 trackResetOnLoad: false,
251 <span id='Ext-form.Basic-cfg-standardSubmit'> /**
252 </span> * @cfg {Boolean} standardSubmit
253 * <p>If set to <tt>true</tt>, a standard HTML form submit is used instead
254 * of a XHR (Ajax) style form submission. Defaults to <tt>false</tt>. All of
255 * the field values, plus any additional params configured via {@link #baseParams}
256 * and/or the <code>options</code> to {@link #submit}, will be included in the
257 * values submitted in the form.</p>
260 <span id='Ext-form.Basic-cfg-waitMsgTarget'> /**
261 </span> * @cfg {Mixed} waitMsgTarget
262 * By default wait messages are displayed with Ext.MessageBox.wait. You can target a specific
263 * element by passing it or its id or mask the form itself by passing in true. Defaults to <tt>undefined</tt>.
271 <span id='Ext-form.Basic-method-destroy'> /**
272 </span> * Destroys this object.
274 destroy: function() {
275 this.clearListeners();
278 <span id='Ext-form.Basic-method-onItemAddOrRemove'> /**
280 * Handle addition or removal of descendant items. Invalidates the cached list of fields
281 * so that {@link #getFields} will do a fresh query next time it is called. Also adds listeners
282 * for state change events on added fields, and tracks components with formBind=true.
284 onItemAddOrRemove: function(parent, child) {
286 isAdding = !!child.ownerCt,
287 isContainer = child.isContainer;
289 function handleField(field) {
290 // Listen for state change events on fields
291 me[isAdding ? 'mon' : 'mun'](field, {
292 validitychange: me.checkValidity,
293 dirtychange: me.checkDirty,
295 buffer: 100 //batch up sequential calls to avoid excessive full-form validation
297 // Flush the cached list of fields
301 if (child.isFormField) {
304 else if (isContainer) {
306 Ext.Array.forEach(child.query('[isFormField]'), handleField);
309 // Flush the cached list of formBind components
310 delete this._boundItems;
312 // Check form bind, but only after initial add
313 if (me.initialized) {
314 me.onValidityChange(!me.hasInvalidField());
318 <span id='Ext-form.Basic-method-getFields'> /**
319 </span> * Return all the {@link Ext.form.field.Field} components in the owner container.
320 * @return {Ext.util.MixedCollection} Collection of the Field objects
322 getFields: function() {
323 var fields = this._fields;
325 fields = this._fields = Ext.create('Ext.util.MixedCollection');
326 fields.addAll(this.owner.query('[isFormField]'));
331 getBoundItems: function() {
332 var boundItems = this._boundItems;
334 boundItems = this._boundItems = Ext.create('Ext.util.MixedCollection');
335 boundItems.addAll(this.owner.query('[formBind]'));
340 <span id='Ext-form.Basic-method-hasInvalidField'> /**
341 </span> * Returns true if the form contains any invalid fields. No fields will be marked as invalid
342 * as a result of calling this; to trigger marking of fields use {@link #isValid} instead.
344 hasInvalidField: function() {
345 return !!this.getFields().findBy(function(field) {
346 var preventMark = field.preventMark,
348 field.preventMark = true;
349 isValid = field.isValid();
350 field.preventMark = preventMark;
355 <span id='Ext-form.Basic-method-isValid'> /**
356 </span> * Returns true if client-side validation on the form is successful. Any invalid fields will be
357 * marked as invalid. If you only want to determine overall form validity without marking anything,
358 * use {@link #hasInvalidField} instead.
361 isValid: function() {
364 me.batchLayouts(function() {
365 invalid = me.getFields().filterBy(function(field) {
366 return !field.validate();
369 return invalid.length < 1;
372 <span id='Ext-form.Basic-method-checkValidity'> /**
373 </span> * Check whether the validity of the entire form has changed since it was last checked, and
374 * if so fire the {@link #validitychange validitychange} event. This is automatically invoked
375 * when an individual field's validity changes.
377 checkValidity: function() {
379 valid = !me.hasInvalidField();
380 if (valid !== me.wasValid) {
381 me.onValidityChange(valid);
382 me.fireEvent('validitychange', me, valid);
387 <span id='Ext-form.Basic-method-onValidityChange'> /**
389 * Handle changes in the form's validity. If there are any sub components with
390 * formBind=true then they are enabled/disabled based on the new validity.
391 * @param {Boolean} valid
393 onValidityChange: function(valid) {
394 var boundItems = this.getBoundItems();
396 boundItems.each(function(cmp) {
397 if (cmp.disabled === valid) {
398 cmp.setDisabled(!valid);
404 <span id='Ext-form.Basic-method-isDirty'> /**
405 </span> * <p>Returns true if any fields in this form have changed from their original values.</p>
406 * <p>Note that if this BasicForm was configured with {@link #trackResetOnLoad} then the
407 * Fields' <em>original values</em> are updated when the values are loaded by {@link #setValues}
408 * or {@link #loadRecord}.</p>
411 isDirty: function() {
412 return !!this.getFields().findBy(function(f) {
417 <span id='Ext-form.Basic-method-checkDirty'> /**
418 </span> * Check whether the dirty state of the entire form has changed since it was last checked, and
419 * if so fire the {@link #dirtychange dirtychange} event. This is automatically invoked
420 * when an individual field's dirty state changes.
422 checkDirty: function() {
423 var dirty = this.isDirty();
424 if (dirty !== this.wasDirty) {
425 this.fireEvent('dirtychange', this, dirty);
426 this.wasDirty = dirty;
430 <span id='Ext-form.Basic-method-hasUpload'> /**
431 </span> * <p>Returns true if the form contains a file upload field. This is used to determine the
432 * method for submitting the form: File uploads are not performed using normal 'Ajax' techniques,
433 * that is they are <b>not</b> performed using XMLHttpRequests. Instead a hidden <tt>&lt;form></tt>
434 * element containing all the fields is created temporarily and submitted with its
435 * <a href="http://www.w3.org/TR/REC-html40/present/frames.html#adef-target">target</a> set to refer
436 * to a dynamically generated, hidden <tt>&lt;iframe></tt> which is inserted into the document
437 * but removed after the return data has been gathered.</p>
438 * <p>The server response is parsed by the browser to create the document for the IFRAME. If the
439 * server is using JSON to send the return object, then the
440 * <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17">Content-Type</a> header
441 * must be set to "text/html" in order to tell the browser to insert the text unchanged into the document body.</p>
442 * <p>Characters which are significant to an HTML parser must be sent as HTML entities, so encode
443 * "&lt;" as "&amp;lt;", "&amp;" as "&amp;amp;" etc.</p>
444 * <p>The response text is retrieved from the document, and a fake XMLHttpRequest object
445 * is created containing a <tt>responseText</tt> property in order to conform to the
446 * requirements of event handlers and callbacks.</p>
447 * <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>
448 * and some server technologies (notably JEE) may require some custom processing in order to
449 * retrieve parameter names and parameter values from the packet content.</p>
452 hasUpload: function() {
453 return !!this.getFields().findBy(function(f) {
454 return f.isFileUpload();
458 <span id='Ext-form.Basic-method-doAction'> /**
459 </span> * Performs a predefined action (an implementation of {@link Ext.form.action.Action})
460 * to perform application-specific processing.
461 * @param {String/Ext.form.action.Action} action The name of the predefined action type,
462 * or instance of {@link Ext.form.action.Action} to perform.
463 * @param {Object} options (optional) The options to pass to the {@link Ext.form.action.Action}
464 * that will get created, if the <tt>action</tt> argument is a String.
465 * <p>All of the config options listed below are supported by both the
466 * {@link Ext.form.action.Submit submit} and {@link Ext.form.action.Load load}
467 * actions unless otherwise noted (custom actions could also accept
468 * other config options):</p><ul>
470 * <li><b>url</b> : String<div class="sub-desc">The url for the action (defaults
471 * to the form's {@link #url}.)</div></li>
473 * <li><b>method</b> : String<div class="sub-desc">The form method to use (defaults
474 * to the form's method, or POST if not defined)</div></li>
476 * <li><b>params</b> : String/Object<div class="sub-desc"><p>The params to pass
477 * (defaults to the form's baseParams, or none if not defined)</p>
478 * <p>Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode Ext.Object.toQueryString}.</p></div></li>
480 * <li><b>headers</b> : Object<div class="sub-desc">Request headers to set for the action.</div></li>
482 * <li><b>success</b> : Function<div class="sub-desc">The callback that will
483 * be invoked after a successful response (see top of
484 * {@link Ext.form.action.Submit submit} and {@link Ext.form.action.Load load}
485 * for a description of what constitutes a successful response).
486 * The function is passed the following parameters:<ul>
487 * <li><tt>form</tt> : The {@link Ext.form.Basic} that requested the action.</li>
488 * <li><tt>action</tt> : The {@link Ext.form.action.Action Action} object which performed the operation.
489 * <div class="sub-desc">The action object contains these properties of interest:<ul>
490 * <li><tt>{@link Ext.form.action.Action#response response}</tt></li>
491 * <li><tt>{@link Ext.form.action.Action#result result}</tt> : interrogate for custom postprocessing</li>
492 * <li><tt>{@link Ext.form.action.Action#type type}</tt></li>
493 * </ul></div></li></ul></div></li>
495 * <li><b>failure</b> : Function<div class="sub-desc">The callback that will be invoked after a
496 * failed transaction attempt. The function is passed the following parameters:<ul>
497 * <li><tt>form</tt> : The {@link Ext.form.Basic} that requested the action.</li>
498 * <li><tt>action</tt> : The {@link Ext.form.action.Action Action} object which performed the operation.
499 * <div class="sub-desc">The action object contains these properties of interest:<ul>
500 * <li><tt>{@link Ext.form.action.Action#failureType failureType}</tt></li>
501 * <li><tt>{@link Ext.form.action.Action#response response}</tt></li>
502 * <li><tt>{@link Ext.form.action.Action#result result}</tt> : interrogate for custom postprocessing</li>
503 * <li><tt>{@link Ext.form.action.Action#type type}</tt></li>
504 * </ul></div></li></ul></div></li>
506 * <li><b>scope</b> : Object<div class="sub-desc">The scope in which to call the
507 * callback functions (The <tt>this</tt> reference for the callback functions).</div></li>
509 * <li><b>clientValidation</b> : Boolean<div class="sub-desc">Submit Action only.
510 * Determines whether a Form's fields are validated in a final call to
511 * {@link Ext.form.Basic#isValid isValid} prior to submission. Set to <tt>false</tt>
512 * to prevent this. If undefined, pre-submission field validation is performed.</div></li></ul>
514 * @return {Ext.form.Basic} this
516 doAction: function(action, options) {
517 if (Ext.isString(action)) {
518 action = Ext.ClassManager.instantiateByAlias('formaction.' + action, Ext.apply({}, options, {form: this}));
520 if (this.fireEvent('beforeaction', this, action) !== false) {
521 this.beforeAction(action);
522 Ext.defer(action.run, 100, action);
527 <span id='Ext-form.Basic-method-submit'> /**
528 </span> * Shortcut to {@link #doAction do} a {@link Ext.form.action.Submit submit action}. This will use the
529 * {@link Ext.form.action.Submit AJAX submit action} by default. If the {@link #standardsubmit} config is
530 * enabled it will use a standard form element to submit, or if the {@link #api} config is present it will
531 * use the {@link Ext.form.action.DirectLoad Ext.direct.Direct submit action}.
532 * @param {Object} options The options to pass to the action (see {@link #doAction} for details).<br>
533 * <p>The following code:</p><pre><code>
534 myFormPanel.getForm().submit({
535 clientValidation: true,
536 url: 'updateConsignment.php',
538 newStatus: 'delivered'
540 success: function(form, action) {
541 Ext.Msg.alert('Success', action.result.msg);
543 failure: function(form, action) {
544 switch (action.failureType) {
545 case Ext.form.action.Action.CLIENT_INVALID:
546 Ext.Msg.alert('Failure', 'Form fields may not be submitted with invalid values');
548 case Ext.form.action.Action.CONNECT_FAILURE:
549 Ext.Msg.alert('Failure', 'Ajax communication failed');
551 case Ext.form.action.Action.SERVER_INVALID:
552 Ext.Msg.alert('Failure', action.result.msg);
556 </code></pre>
557 * would process the following server response for a successful submission:<pre><code>
559 "success":true, // note this is Boolean, not string
560 "msg":"Consignment updated"
562 </code></pre>
563 * and the following server response for a failed submission:<pre><code>
565 "success":false, // note this is Boolean, not string
566 "msg":"You do not have permission to perform this operation"
568 </code></pre>
569 * @return {Ext.form.Basic} this
571 submit: function(options) {
572 return this.doAction(this.standardSubmit ? 'standardsubmit' : this.api ? 'directsubmit' : 'submit', options);
575 <span id='Ext-form.Basic-method-load'> /**
576 </span> * Shortcut to {@link #doAction do} a {@link Ext.form.action.Load load action}.
577 * @param {Object} options The options to pass to the action (see {@link #doAction} for details)
578 * @return {Ext.form.Basic} this
580 load: function(options) {
581 return this.doAction(this.api ? 'directload' : 'load', options);
584 <span id='Ext-form.Basic-method-updateRecord'> /**
585 </span> * Persists the values in this form into the passed {@link Ext.data.Model} object in a beginEdit/endEdit block.
586 * @param {Ext.data.Record} record The record to edit
587 * @return {Ext.form.Basic} this
589 updateRecord: function(record) {
590 var fields = record.fields,
591 values = this.getFieldValues(),
595 fields.each(function(f) {
597 if (name in values) {
598 obj[name] = values[name];
609 <span id='Ext-form.Basic-method-loadRecord'> /**
610 </span> * Loads an {@link Ext.data.Model} into this form by calling {@link #setValues} with the
611 * {@link Ext.data.Model#data record data}.
612 * See also {@link #trackResetOnLoad}.
613 * @param {Ext.data.Model} record The record to load
614 * @return {Ext.form.Basic} this
616 loadRecord: function(record) {
617 this._record = record;
618 return this.setValues(record.data);
621 <span id='Ext-form.Basic-method-getRecord'> /**
622 </span> * Returns the last Ext.data.Model instance that was loaded via {@link #loadRecord}
623 * @return {Ext.data.Model} The record
625 getRecord: function() {
629 <span id='Ext-form.Basic-method-beforeAction'> /**
631 * Called before an action is performed via {@link #doAction}.
632 * @param {Ext.form.action.Action} action The Action instance that was invoked
634 beforeAction: function(action) {
635 var waitMsg = action.waitMsg,
636 maskCls = Ext.baseCSSPrefix + 'mask-loading',
639 // Call HtmlEditor's syncValue before actions
640 this.getFields().each(function(f) {
641 if (f.isFormField && f.syncValue) {
647 waitMsgTarget = this.waitMsgTarget;
648 if (waitMsgTarget === true) {
649 this.owner.el.mask(waitMsg, maskCls);
650 } else if (waitMsgTarget) {
651 waitMsgTarget = this.waitMsgTarget = Ext.get(waitMsgTarget);
652 waitMsgTarget.mask(waitMsg, maskCls);
654 Ext.MessageBox.wait(waitMsg, action.waitTitle || this.waitTitle);
659 <span id='Ext-form.Basic-method-afterAction'> /**
661 * Called after an action is performed via {@link #doAction}.
662 * @param {Ext.form.action.Action} action The Action instance that was invoked
663 * @param {Boolean} success True if the action completed successfully, false, otherwise.
665 afterAction: function(action, success) {
666 if (action.waitMsg) {
667 var MessageBox = Ext.MessageBox,
668 waitMsgTarget = this.waitMsgTarget;
669 if (waitMsgTarget === true) {
670 this.owner.el.unmask();
671 } else if (waitMsgTarget) {
672 waitMsgTarget.unmask();
674 MessageBox.updateProgress(1);
682 Ext.callback(action.success, action.scope || action, [this, action]);
683 this.fireEvent('actioncomplete', this, action);
685 Ext.callback(action.failure, action.scope || action, [this, action]);
686 this.fireEvent('actionfailed', this, action);
691 <span id='Ext-form.Basic-method-findField'> /**
692 </span> * Find a specific {@link Ext.form.field.Field} in this form by id or name.
693 * @param {String} id The value to search for (specify either a {@link Ext.Component#id id} or
694 * {@link Ext.form.field.Field#getName name or hiddenName}).
695 * @return Ext.form.field.Field The first matching field, or <tt>null</tt> if none was found.
697 findField: function(id) {
698 return this.getFields().findBy(function(f) {
699 return f.id === id || f.getName() === id;
704 <span id='Ext-form.Basic-method-markInvalid'> /**
705 </span> * Mark fields in this form invalid in bulk.
706 * @param {Array/Object} errors Either an array in the form <code>[{id:'fieldId', msg:'The message'}, ...]</code>,
707 * an object hash of <code>{id: msg, id2: msg2}</code>, or a {@link Ext.data.Errors} object.
708 * @return {Ext.form.Basic} this
710 markInvalid: function(errors) {
713 function mark(fieldId, msg) {
714 var field = me.findField(fieldId);
716 field.markInvalid(msg);
720 if (Ext.isArray(errors)) {
721 Ext.each(errors, function(err) {
722 mark(err.id, err.msg);
725 else if (errors instanceof Ext.data.Errors) {
726 errors.each(function(err) {
727 mark(err.field, err.message);
731 Ext.iterate(errors, mark);
736 <span id='Ext-form.Basic-method-setValues'> /**
737 </span> * Set values for fields in this form in bulk.
738 * @param {Array/Object} values Either an array in the form:<pre><code>
739 [{id:'clientName', value:'Fred. Olsen Lines'},
740 {id:'portOfLoading', value:'FXT'},
741 {id:'portOfDischarge', value:'OSL'} ]</code></pre>
742 * or an object hash of the form:<pre><code>
744 clientName: 'Fred. Olsen Lines',
745 portOfLoading: 'FXT',
746 portOfDischarge: 'OSL'
747 }</code></pre>
748 * @return {Ext.form.Basic} this
750 setValues: function(values) {
753 function setVal(fieldId, val) {
754 var field = me.findField(fieldId);
757 if (me.trackResetOnLoad) {
758 field.resetOriginalValue();
763 if (Ext.isArray(values)) {
765 Ext.each(values, function(val) {
766 setVal(val.id, val.value);
770 Ext.iterate(values, setVal);
775 <span id='Ext-form.Basic-method-getValues'> /**
776 </span> * Retrieves the fields in the form as a set of key/value pairs, using their
777 * {@link Ext.form.field.Field#getSubmitData getSubmitData()} method to collect the values.
778 * If multiple fields return values under the same name those values will be combined into an Array.
779 * This is similar to {@link #getFieldValues} except that this method collects only String values for
780 * submission, while getFieldValues collects type-specific data values (e.g. Date objects for date fields.)
781 * @param {Boolean} asString (optional) If true, will return the key/value collection as a single
782 * URL-encoded param string. Defaults to false.
783 * @param {Boolean} dirtyOnly (optional) If true, only fields that are dirty will be included in the result.
785 * @param {Boolean} includeEmptyText (optional) If true, the configured emptyText of empty fields will be used.
787 * @return {String/Object}
789 getValues: function(asString, dirtyOnly, includeEmptyText, useDataValues) {
792 this.getFields().each(function(field) {
793 if (!dirtyOnly || field.isDirty()) {
794 var data = field[useDataValues ? 'getModelData' : 'getSubmitData'](includeEmptyText);
795 if (Ext.isObject(data)) {
796 Ext.iterate(data, function(name, val) {
797 if (includeEmptyText && val === '') {
798 val = field.emptyText || '';
800 if (name in values) {
801 var bucket = values[name],
802 isArray = Ext.isArray;
803 if (!isArray(bucket)) {
804 bucket = values[name] = [bucket];
807 values[name] = bucket.concat(val);
820 values = Ext.Object.toQueryString(values);
825 <span id='Ext-form.Basic-method-getFieldValues'> /**
826 </span> * Retrieves the fields in the form as a set of key/value pairs, using their
827 * {@link Ext.form.field.Field#getModelData getModelData()} method to collect the values.
828 * If multiple fields return values under the same name those values will be combined into an Array.
829 * This is similar to {@link #getValues} except that this method collects type-specific data values
830 * (e.g. Date objects for date fields) while getValues returns only String values for submission.
831 * @param {Boolean} dirtyOnly (optional) If true, only fields that are dirty will be included in the result.
835 getFieldValues: function(dirtyOnly) {
836 return this.getValues(false, dirtyOnly, false, true);
839 <span id='Ext-form.Basic-method-clearInvalid'> /**
840 </span> * Clears all invalid field messages in this form.
841 * @return {Ext.form.Basic} this
843 clearInvalid: function() {
845 me.batchLayouts(function() {
846 me.getFields().each(function(f) {
853 <span id='Ext-form.Basic-method-reset'> /**
854 </span> * Resets all fields in this form.
855 * @return {Ext.form.Basic} this
859 me.batchLayouts(function() {
860 me.getFields().each(function(f) {
867 <span id='Ext-form.Basic-method-applyToFields'> /**
868 </span> * Calls {@link Ext#apply Ext.apply} for all fields in this form with the passed object.
869 * @param {Object} obj The object to be applied
870 * @return {Ext.form.Basic} this
872 applyToFields: function(obj) {
873 this.getFields().each(function(f) {
879 <span id='Ext-form.Basic-method-applyIfToFields'> /**
880 </span> * Calls {@link Ext#applyIf Ext.applyIf} for all field in this form with the passed object.
881 * @param {Object} obj The object to be applied
882 * @return {Ext.form.Basic} this
884 applyIfToFields: function(obj) {
885 this.getFields().each(function(f) {
891 <span id='Ext-form.Basic-method-batchLayouts'> /**
893 * Utility wrapper that suspends layouts of all field parent containers for the duration of a given
894 * function. Used during full-form validation and resets to prevent huge numbers of layouts.
895 * @param {Function} fn
897 batchLayouts: function(fn) {
899 suspended = new Ext.util.HashMap();
901 // Temporarily suspend layout on each field's immediate owner so we don't get a huge layout cascade
902 me.getFields().each(function(field) {
903 var ownerCt = field.ownerCt;
904 if (!suspended.contains(ownerCt)) {
905 suspended.add(ownerCt);
906 ownerCt.oldSuspendLayout = ownerCt.suspendLayout;
907 ownerCt.suspendLayout = true;
911 // Invoke the function
914 // Un-suspend the container layouts
915 suspended.each(function(id, ct) {
916 ct.suspendLayout = ct.oldSuspendLayout;
917 delete ct.oldSuspendLayout;
920 // Trigger a single layout
921 me.owner.doComponentLayout();
924 </pre></pre></body></html>