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.

372 lines
16 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-FormPanel-method-constructor'><span id='Ext-form-FormPanel'>/**
  19. </span></span> * @class Ext.form.FormPanel
  20. * @extends Ext.Panel
  21. * &lt;p&gt;Standard form container.&lt;/p&gt;
  22. *
  23. * &lt;p&gt;&lt;b&gt;&lt;u&gt;Layout&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;
  24. * &lt;p&gt;By default, FormPanel is configured with &lt;tt&gt;layout:'form'&lt;/tt&gt; to use an {@link Ext.layout.FormLayout}
  25. * layout manager, which styles and renders fields and labels correctly. When nesting additional Containers
  26. * within a FormPanel, you should ensure that any descendant Containers which host input Fields use the
  27. * {@link Ext.layout.FormLayout} layout manager.&lt;/p&gt;
  28. *
  29. * &lt;p&gt;&lt;b&gt;&lt;u&gt;BasicForm&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;
  30. * &lt;p&gt;Although &lt;b&gt;not listed&lt;/b&gt; as configuration options of FormPanel, the FormPanel class accepts all
  31. * of the config options required to configure its internal {@link Ext.form.BasicForm} for:
  32. * &lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  33. * &lt;li&gt;{@link Ext.form.BasicForm#fileUpload file uploads}&lt;/li&gt;
  34. * &lt;li&gt;functionality for {@link Ext.form.BasicForm#doAction loading, validating and submitting} the form&lt;/li&gt;
  35. * &lt;/ul&gt;&lt;/div&gt;
  36. *
  37. * &lt;p&gt;&lt;b&gt;Note&lt;/b&gt;: If subclassing FormPanel, any configuration options for the BasicForm must be applied to
  38. * the &lt;tt&gt;&lt;b&gt;initialConfig&lt;/b&gt;&lt;/tt&gt; property of the FormPanel. Applying {@link Ext.form.BasicForm BasicForm}
  39. * configuration settings to &lt;b&gt;&lt;tt&gt;this&lt;/tt&gt;&lt;/b&gt; will &lt;b&gt;not&lt;/b&gt; affect the BasicForm's configuration.&lt;/p&gt;
  40. *
  41. * &lt;p&gt;&lt;b&gt;&lt;u&gt;Form Validation&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;
  42. * &lt;p&gt;For information on form validation see the following:&lt;/p&gt;
  43. * &lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  44. * &lt;li&gt;{@link Ext.form.TextField}&lt;/li&gt;
  45. * &lt;li&gt;{@link Ext.form.VTypes}&lt;/li&gt;
  46. * &lt;li&gt;{@link Ext.form.BasicForm#doAction BasicForm.doAction &lt;b&gt;clientValidation&lt;/b&gt; notes}&lt;/li&gt;
  47. * &lt;li&gt;&lt;tt&gt;{@link Ext.form.FormPanel#monitorValid monitorValid}&lt;/tt&gt;&lt;/li&gt;
  48. * &lt;/ul&gt;&lt;/div&gt;
  49. *
  50. * &lt;p&gt;&lt;b&gt;&lt;u&gt;Form Submission&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;
  51. * &lt;p&gt;By default, Ext Forms are submitted through Ajax, using {@link Ext.form.Action}. To enable normal browser
  52. * submission of the {@link Ext.form.BasicForm BasicForm} contained in this FormPanel, see the
  53. * &lt;tt&gt;&lt;b&gt;{@link Ext.form.BasicForm#standardSubmit standardSubmit}&lt;/b&gt;&lt;/tt&gt; option.&lt;/p&gt;
  54. *
  55. * @constructor
  56. * @param {Object} config Configuration options
  57. * @xtype form
  58. */
  59. Ext.FormPanel = Ext.extend(Ext.Panel, {
  60. <span id='Ext-form-FormPanel-cfg-formId'> /**
  61. </span> * @cfg {String} formId (optional) The id of the FORM tag (defaults to an auto-generated id).
  62. */
  63. <span id='Ext-form-FormPanel-cfg-hideLabels'> /**
  64. </span> * @cfg {Boolean} hideLabels
  65. * &lt;p&gt;&lt;tt&gt;true&lt;/tt&gt; to hide field labels by default (sets &lt;tt&gt;display:none&lt;/tt&gt;). Defaults to
  66. * &lt;tt&gt;false&lt;/tt&gt;.&lt;/p&gt;
  67. * &lt;p&gt;Also see {@link Ext.Component}.&lt;tt&gt;{@link Ext.Component#hideLabel hideLabel}&lt;/tt&gt;.
  68. */
  69. <span id='Ext-form-FormPanel-cfg-labelPad'> /**
  70. </span> * @cfg {Number} labelPad
  71. * The default padding in pixels for field labels (defaults to &lt;tt&gt;5&lt;/tt&gt;). &lt;tt&gt;labelPad&lt;/tt&gt; only
  72. * applies if &lt;tt&gt;{@link #labelWidth}&lt;/tt&gt; is also specified, otherwise it will be ignored.
  73. */
  74. <span id='Ext-form-FormPanel-cfg-labelSeparator'> /**
  75. </span> * @cfg {String} labelSeparator
  76. * See {@link Ext.Component}.&lt;tt&gt;{@link Ext.Component#labelSeparator labelSeparator}&lt;/tt&gt;
  77. */
  78. <span id='Ext-form-FormPanel-cfg-labelWidth'> /**
  79. </span> * @cfg {Number} labelWidth The width of labels in pixels. This property cascades to child containers
  80. * and can be overridden on any child container (e.g., a fieldset can specify a different &lt;tt&gt;labelWidth&lt;/tt&gt;
  81. * for its fields) (defaults to &lt;tt&gt;100&lt;/tt&gt;).
  82. */
  83. <span id='Ext-form-FormPanel-cfg-itemCls'> /**
  84. </span> * @cfg {String} itemCls A css class to apply to the x-form-item of fields. This property cascades to child containers.
  85. */
  86. <span id='Ext-form-FormPanel-cfg-buttons'> /**
  87. </span> * @cfg {Array} buttons
  88. * An array of {@link Ext.Button}s or {@link Ext.Button} configs used to add buttons to the footer of this FormPanel.&lt;br&gt;
  89. * &lt;p&gt;Buttons in the footer of a FormPanel may be configured with the option &lt;tt&gt;formBind: true&lt;/tt&gt;. This causes
  90. * the form's {@link #monitorValid valid state monitor task} to enable/disable those Buttons depending on
  91. * the form's valid/invalid state.&lt;/p&gt;
  92. */
  93. <span id='Ext-form-FormPanel-cfg-minButtonWidth'> /**
  94. </span> * @cfg {Number} minButtonWidth Minimum width of all buttons in pixels (defaults to &lt;tt&gt;75&lt;/tt&gt;).
  95. */
  96. minButtonWidth : 75,
  97. <span id='Ext-form-FormPanel-cfg-labelAlign'> /**
  98. </span> * @cfg {String} labelAlign The label alignment value used for the &lt;tt&gt;text-align&lt;/tt&gt; specification
  99. * for the &lt;b&gt;container&lt;/b&gt;. Valid values are &lt;tt&gt;&quot;left&lt;/tt&gt;&quot;, &lt;tt&gt;&quot;top&quot;&lt;/tt&gt; or &lt;tt&gt;&quot;right&quot;&lt;/tt&gt;
  100. * (defaults to &lt;tt&gt;&quot;left&quot;&lt;/tt&gt;). This property cascades to child &lt;b&gt;containers&lt;/b&gt; and can be
  101. * overridden on any child &lt;b&gt;container&lt;/b&gt; (e.g., a fieldset can specify a different &lt;tt&gt;labelAlign&lt;/tt&gt;
  102. * for its fields).
  103. */
  104. labelAlign : 'left',
  105. <span id='Ext-form-FormPanel-cfg-monitorValid'> /**
  106. </span> * @cfg {Boolean} monitorValid If &lt;tt&gt;true&lt;/tt&gt;, the form monitors its valid state &lt;b&gt;client-side&lt;/b&gt; and
  107. * regularly fires the {@link #clientvalidation} event passing that state.&lt;br&gt;
  108. * &lt;p&gt;When monitoring valid state, the FormPanel enables/disables any of its configured
  109. * {@link #buttons} which have been configured with &lt;code&gt;formBind: true&lt;/code&gt; depending
  110. * on whether the {@link Ext.form.BasicForm#isValid form is valid} or not. Defaults to &lt;tt&gt;false&lt;/tt&gt;&lt;/p&gt;
  111. */
  112. monitorValid : false,
  113. <span id='Ext-form-FormPanel-cfg-monitorPoll'> /**
  114. </span> * @cfg {Number} monitorPoll The milliseconds to poll valid state, ignored if monitorValid is not true (defaults to 200)
  115. */
  116. monitorPoll : 200,
  117. <span id='Ext-form-FormPanel-cfg-layout'> /**
  118. </span> * @cfg {String} layout Defaults to &lt;tt&gt;'form'&lt;/tt&gt;. Normally this configuration property should not be altered.
  119. * For additional details see {@link Ext.layout.FormLayout} and {@link Ext.Container#layout Ext.Container.layout}.
  120. */
  121. layout : 'form',
  122. <span id='Ext-form-FormPanel-method-initComponent'> // private
  123. </span> initComponent : function(){
  124. this.form = this.createForm();
  125. Ext.FormPanel.superclass.initComponent.call(this);
  126. this.bodyCfg = {
  127. tag: 'form',
  128. cls: this.baseCls + '-body',
  129. method : this.method || 'POST',
  130. id : this.formId || Ext.id()
  131. };
  132. if(this.fileUpload) {
  133. this.bodyCfg.enctype = 'multipart/form-data';
  134. }
  135. this.initItems();
  136. this.addEvents(
  137. <span id='Ext-form-FormPanel-event-clientvalidation'> /**
  138. </span> * @event clientvalidation
  139. * If the monitorValid config option is true, this event fires repetitively to notify of valid state
  140. * @param {Ext.form.FormPanel} this
  141. * @param {Boolean} valid true if the form has passed client-side validation
  142. */
  143. 'clientvalidation'
  144. );
  145. this.relayEvents(this.form, ['beforeaction', 'actionfailed', 'actioncomplete']);
  146. },
  147. <span id='Ext-form-FormPanel-method-createForm'> // private
  148. </span> createForm : function(){
  149. var config = Ext.applyIf({listeners: {}}, this.initialConfig);
  150. return new Ext.form.BasicForm(null, config);
  151. },
  152. <span id='Ext-form-FormPanel-method-initFields'> // private
  153. </span> initFields : function(){
  154. var f = this.form;
  155. var formPanel = this;
  156. var fn = function(c){
  157. if(formPanel.isField(c)){
  158. f.add(c);
  159. }else if(c.findBy &amp;&amp; c != formPanel){
  160. formPanel.applySettings(c);
  161. //each check required for check/radio groups.
  162. if(c.items &amp;&amp; c.items.each){
  163. c.items.each(fn, this);
  164. }
  165. }
  166. };
  167. this.items.each(fn, this);
  168. },
  169. <span id='Ext-form-FormPanel-method-applySettings'> // private
  170. </span> applySettings: function(c){
  171. var ct = c.ownerCt;
  172. Ext.applyIf(c, {
  173. labelAlign: ct.labelAlign,
  174. labelWidth: ct.labelWidth,
  175. itemCls: ct.itemCls
  176. });
  177. },
  178. <span id='Ext-form-FormPanel-method-getLayoutTarget'> // private
  179. </span> getLayoutTarget : function(){
  180. return this.form.el;
  181. },
  182. <span id='Ext-form-FormPanel-method-getForm'> /**
  183. </span> * Provides access to the {@link Ext.form.BasicForm Form} which this Panel contains.
  184. * @return {Ext.form.BasicForm} The {@link Ext.form.BasicForm Form} which this Panel contains.
  185. */
  186. getForm : function(){
  187. return this.form;
  188. },
  189. <span id='Ext-form-FormPanel-method-onRender'> // private
  190. </span> onRender : function(ct, position){
  191. this.initFields();
  192. Ext.FormPanel.superclass.onRender.call(this, ct, position);
  193. this.form.initEl(this.body);
  194. },
  195. <span id='Ext-form-FormPanel-method-beforeDestroy'> // private
  196. </span> beforeDestroy : function(){
  197. this.stopMonitoring();
  198. this.form.destroy(true);
  199. Ext.FormPanel.superclass.beforeDestroy.call(this);
  200. },
  201. <span id='Ext-form-FormPanel-method-isField'> // Determine if a Component is usable as a form Field.
  202. </span> isField : function(c) {
  203. return !!c.setValue &amp;&amp; !!c.getValue &amp;&amp; !!c.markInvalid &amp;&amp; !!c.clearInvalid;
  204. },
  205. <span id='Ext-form-FormPanel-method-initEvents'> // private
  206. </span> initEvents : function(){
  207. Ext.FormPanel.superclass.initEvents.call(this);
  208. // Listeners are required here to catch bubbling events from children.
  209. this.on({
  210. scope: this,
  211. add: this.onAddEvent,
  212. remove: this.onRemoveEvent
  213. });
  214. if(this.monitorValid){ // initialize after render
  215. this.startMonitoring();
  216. }
  217. },
  218. <span id='Ext-form-FormPanel-method-onAdd'> // private
  219. </span> onAdd: function(c){
  220. Ext.FormPanel.superclass.onAdd.call(this, c);
  221. this.processAdd(c);
  222. },
  223. <span id='Ext-form-FormPanel-method-onAddEvent'> // private
  224. </span> onAddEvent: function(ct, c){
  225. if(ct !== this){
  226. this.processAdd(c);
  227. }
  228. },
  229. <span id='Ext-form-FormPanel-method-processAdd'> // private
  230. </span> processAdd : function(c){
  231. // If a single form Field, add it
  232. if(this.isField(c)){
  233. this.form.add(c);
  234. // If a Container, add any Fields it might contain
  235. }else if(c.findBy){
  236. this.applySettings(c);
  237. this.form.add.apply(this.form, c.findBy(this.isField));
  238. }
  239. },
  240. <span id='Ext-form-FormPanel-method-onRemove'> // private
  241. </span> onRemove: function(c){
  242. Ext.FormPanel.superclass.onRemove.call(this, c);
  243. this.processRemove(c);
  244. },
  245. <span id='Ext-form-FormPanel-method-onRemoveEvent'> onRemoveEvent: function(ct, c){
  246. </span> if(ct !== this){
  247. this.processRemove(c);
  248. }
  249. },
  250. <span id='Ext-form-FormPanel-method-processRemove'> // private
  251. </span> processRemove: function(c){
  252. if(!this.destroying){
  253. // If a single form Field, remove it
  254. if(this.isField(c)){
  255. this.form.remove(c);
  256. // If a Container, its already destroyed by the time it gets here. Remove any references to destroyed fields.
  257. }else if (c.findBy){
  258. Ext.each(c.findBy(this.isField), this.form.remove, this.form);
  259. /*
  260. * This isn't the most efficient way of getting rid of the items, however it's the most
  261. * correct, which in this case is most important.
  262. */
  263. this.form.cleanDestroyed();
  264. }
  265. }
  266. },
  267. <span id='Ext-form-FormPanel-method-startMonitoring'> /**
  268. </span> * Starts monitoring of the valid state of this form. Usually this is done by passing the config
  269. * option &quot;monitorValid&quot;
  270. */
  271. startMonitoring : function(){
  272. if(!this.validTask){
  273. this.validTask = new Ext.util.TaskRunner();
  274. this.validTask.start({
  275. run : this.bindHandler,
  276. interval : this.monitorPoll || 200,
  277. scope: this
  278. });
  279. }
  280. },
  281. <span id='Ext-form-FormPanel-method-stopMonitoring'> /**
  282. </span> * Stops monitoring of the valid state of this form
  283. */
  284. stopMonitoring : function(){
  285. if(this.validTask){
  286. this.validTask.stopAll();
  287. this.validTask = null;
  288. }
  289. },
  290. <span id='Ext-form-FormPanel-method-load'> /**
  291. </span> * This is a proxy for the underlying BasicForm's {@link Ext.form.BasicForm#load} call.
  292. * @param {Object} options The options to pass to the action (see {@link Ext.form.BasicForm#doAction} for details)
  293. */
  294. load : function(){
  295. this.form.load.apply(this.form, arguments);
  296. },
  297. <span id='Ext-form-FormPanel-method-onDisable'> // private
  298. </span> onDisable : function(){
  299. Ext.FormPanel.superclass.onDisable.call(this);
  300. if(this.form){
  301. this.form.items.each(function(){
  302. this.disable();
  303. });
  304. }
  305. },
  306. <span id='Ext-form-FormPanel-method-onEnable'> // private
  307. </span> onEnable : function(){
  308. Ext.FormPanel.superclass.onEnable.call(this);
  309. if(this.form){
  310. this.form.items.each(function(){
  311. this.enable();
  312. });
  313. }
  314. },
  315. <span id='Ext-form-FormPanel-method-bindHandler'> // private
  316. </span> bindHandler : function(){
  317. var valid = true;
  318. this.form.items.each(function(f){
  319. if(!f.isValid(true)){
  320. valid = false;
  321. return false;
  322. }
  323. });
  324. if(this.fbar){
  325. var fitems = this.fbar.items.items;
  326. for(var i = 0, len = fitems.length; i &lt; len; i++){
  327. var btn = fitems[i];
  328. if(btn.formBind === true &amp;&amp; btn.disabled === valid){
  329. btn.setDisabled(!valid);
  330. }
  331. }
  332. }
  333. this.fireEvent('clientvalidation', this, valid);
  334. }
  335. });
  336. Ext.reg('form', Ext.FormPanel);
  337. Ext.form.FormPanel = Ext.FormPanel;
  338. </pre>
  339. </body>
  340. </html>