You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

824 lines
36 KiB

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