Panel5.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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-Panel'>/**
  19. </span> * @docauthor Jason Johnston &lt;jason@sencha.com&gt;
  20. *
  21. * FormPanel provides a standard container for forms. It is essentially a standard {@link Ext.panel.Panel} which
  22. * automatically creates a {@link Ext.form.Basic BasicForm} for managing any {@link Ext.form.field.Field}
  23. * objects that are added as descendants of the panel. It also includes conveniences for configuring and
  24. * working with the BasicForm and the collection of Fields.
  25. *
  26. * # Layout
  27. *
  28. * By default, FormPanel is configured with `{@link Ext.layout.container.Anchor layout:'anchor'}` for
  29. * the layout of its immediate child items. This can be changed to any of the supported container layouts.
  30. * The layout of sub-containers is configured in {@link Ext.container.Container#layout the standard way}.
  31. *
  32. * # BasicForm
  33. *
  34. * Although **not listed** as configuration options of FormPanel, the FormPanel class accepts all
  35. * of the config options supported by the {@link Ext.form.Basic} class, and will pass them along to
  36. * the internal BasicForm when it is created.
  37. *
  38. * The following events fired by the BasicForm will be re-fired by the FormPanel and can therefore be
  39. * listened for on the FormPanel itself:
  40. *
  41. * - {@link Ext.form.Basic#beforeaction beforeaction}
  42. * - {@link Ext.form.Basic#actionfailed actionfailed}
  43. * - {@link Ext.form.Basic#actioncomplete actioncomplete}
  44. * - {@link Ext.form.Basic#validitychange validitychange}
  45. * - {@link Ext.form.Basic#dirtychange dirtychange}
  46. *
  47. * # Field Defaults
  48. *
  49. * The {@link #fieldDefaults} config option conveniently allows centralized configuration of default values
  50. * for all fields added as descendants of the FormPanel. Any config option recognized by implementations
  51. * of {@link Ext.form.Labelable} may be included in this object. See the {@link #fieldDefaults} documentation
  52. * for details of how the defaults are applied.
  53. *
  54. * # Form Validation
  55. *
  56. * With the default configuration, form fields are validated on-the-fly while the user edits their values.
  57. * This can be controlled on a per-field basis (or via the {@link #fieldDefaults} config) with the field
  58. * config properties {@link Ext.form.field.Field#validateOnChange} and {@link Ext.form.field.Base#checkChangeEvents},
  59. * and the FormPanel's config properties {@link #pollForChanges} and {@link #pollInterval}.
  60. *
  61. * Any component within the FormPanel can be configured with `formBind: true`. This will cause that
  62. * component to be automatically disabled when the form is invalid, and enabled when it is valid. This is most
  63. * commonly used for Button components to prevent submitting the form in an invalid state, but can be used on
  64. * any component type.
  65. *
  66. * For more information on form validation see the following:
  67. *
  68. * - {@link Ext.form.field.Field#validateOnChange}
  69. * - {@link #pollForChanges} and {@link #pollInterval}
  70. * - {@link Ext.form.field.VTypes}
  71. * - {@link Ext.form.Basic#doAction BasicForm.doAction clientValidation notes}
  72. *
  73. * # Form Submission
  74. *
  75. * By default, Ext Forms are submitted through Ajax, using {@link Ext.form.action.Action}. See the documentation for
  76. * {@link Ext.form.Basic} for details.
  77. *
  78. * # Example usage
  79. *
  80. * @example
  81. * Ext.create('Ext.form.Panel', {
  82. * title: 'Simple Form',
  83. * bodyPadding: 5,
  84. * width: 350,
  85. *
  86. * // The form will submit an AJAX request to this URL when submitted
  87. * url: 'save-form.php',
  88. *
  89. * // Fields will be arranged vertically, stretched to full width
  90. * layout: 'anchor',
  91. * defaults: {
  92. * anchor: '100%'
  93. * },
  94. *
  95. * // The fields
  96. * defaultType: 'textfield',
  97. * items: [{
  98. * fieldLabel: 'First Name',
  99. * name: 'first',
  100. * allowBlank: false
  101. * },{
  102. * fieldLabel: 'Last Name',
  103. * name: 'last',
  104. * allowBlank: false
  105. * }],
  106. *
  107. * // Reset and Submit buttons
  108. * buttons: [{
  109. * text: 'Reset',
  110. * handler: function() {
  111. * this.up('form').getForm().reset();
  112. * }
  113. * }, {
  114. * text: 'Submit',
  115. * formBind: true, //only enabled once the form is valid
  116. * disabled: true,
  117. * handler: function() {
  118. * var form = this.up('form').getForm();
  119. * if (form.isValid()) {
  120. * form.submit({
  121. * success: function(form, action) {
  122. * Ext.Msg.alert('Success', action.result.msg);
  123. * },
  124. * failure: function(form, action) {
  125. * Ext.Msg.alert('Failed', action.result.msg);
  126. * }
  127. * });
  128. * }
  129. * }
  130. * }],
  131. * renderTo: Ext.getBody()
  132. * });
  133. *
  134. */
  135. Ext.define('Ext.form.Panel', {
  136. extend:'Ext.panel.Panel',
  137. mixins: {
  138. fieldAncestor: 'Ext.form.FieldAncestor'
  139. },
  140. alias: 'widget.form',
  141. alternateClassName: ['Ext.FormPanel', 'Ext.form.FormPanel'],
  142. requires: ['Ext.form.Basic', 'Ext.util.TaskRunner'],
  143. <span id='Ext-form-Panel-cfg-pollForChanges'> /**
  144. </span> * @cfg {Boolean} pollForChanges
  145. * If set to `true`, sets up an interval task (using the {@link #pollInterval}) in which the
  146. * panel's fields are repeatedly checked for changes in their values. This is in addition to the normal detection
  147. * each field does on its own input element, and is not needed in most cases. It does, however, provide a
  148. * means to absolutely guarantee detection of all changes including some edge cases in some browsers which
  149. * do not fire native events. Defaults to `false`.
  150. */
  151. <span id='Ext-form-Panel-cfg-pollInterval'> /**
  152. </span> * @cfg {Number} pollInterval
  153. * Interval in milliseconds at which the form's fields are checked for value changes. Only used if
  154. * the {@link #pollForChanges} option is set to `true`. Defaults to 500 milliseconds.
  155. */
  156. <span id='Ext-form-Panel-cfg-layout'> /**
  157. </span> * @cfg {String} layout
  158. * The {@link Ext.container.Container#layout} for the form panel's immediate child items.
  159. * Defaults to `'anchor'`.
  160. */
  161. layout: 'anchor',
  162. ariaRole: 'form',
  163. basicFormConfigs: [
  164. 'api',
  165. 'baseParams',
  166. 'errorReader',
  167. 'method',
  168. 'paramOrder',
  169. 'paramsAsHash',
  170. 'reader',
  171. 'standardSubmit',
  172. 'timeout',
  173. 'trackResetOnLoad',
  174. 'url',
  175. 'waitMsgTarget',
  176. 'waitTitle'
  177. ],
  178. initComponent: function() {
  179. var me = this;
  180. if (me.frame) {
  181. me.border = false;
  182. }
  183. me.initFieldAncestor();
  184. me.callParent();
  185. me.relayEvents(me.form, [
  186. <span id='Ext-form-Panel-event-beforeaction'> /**
  187. </span> * @event beforeaction
  188. * @inheritdoc Ext.form.Basic#beforeaction
  189. */
  190. 'beforeaction',
  191. <span id='Ext-form-Panel-event-actionfailed'> /**
  192. </span> * @event actionfailed
  193. * @inheritdoc Ext.form.Basic#actionfailed
  194. */
  195. 'actionfailed',
  196. <span id='Ext-form-Panel-event-actioncomplete'> /**
  197. </span> * @event actioncomplete
  198. * @inheritdoc Ext.form.Basic#actioncomplete
  199. */
  200. 'actioncomplete',
  201. <span id='Ext-form-Panel-event-validitychange'> /**
  202. </span> * @event validitychange
  203. * @inheritdoc Ext.form.Basic#validitychange
  204. */
  205. 'validitychange',
  206. <span id='Ext-form-Panel-event-dirtychange'> /**
  207. </span> * @event dirtychange
  208. * @inheritdoc Ext.form.Basic#dirtychange
  209. */
  210. 'dirtychange'
  211. ]);
  212. // Start polling if configured
  213. if (me.pollForChanges) {
  214. me.startPolling(me.pollInterval || 500);
  215. }
  216. },
  217. initItems: function() {
  218. // Create the BasicForm
  219. var me = this;
  220. me.form = me.createForm();
  221. me.callParent();
  222. },
  223. // Initialize the BasicForm after all layouts have been completed.
  224. afterFirstLayout: function() {
  225. this.callParent();
  226. this.form.initialize();
  227. },
  228. <span id='Ext-form-Panel-method-createForm'> /**
  229. </span> * @private
  230. */
  231. createForm: function() {
  232. var cfg = {},
  233. props = this.basicFormConfigs,
  234. len = props.length,
  235. i = 0,
  236. prop;
  237. for (; i &lt; len; ++i) {
  238. prop = props[i];
  239. cfg[prop] = this[prop];
  240. }
  241. return new Ext.form.Basic(this, cfg);
  242. },
  243. <span id='Ext-form-Panel-method-getForm'> /**
  244. </span> * Provides access to the {@link Ext.form.Basic Form} which this Panel contains.
  245. * @return {Ext.form.Basic} The {@link Ext.form.Basic Form} which this Panel contains.
  246. */
  247. getForm: function() {
  248. return this.form;
  249. },
  250. <span id='Ext-form-Panel-method-loadRecord'> /**
  251. </span> * Loads an {@link Ext.data.Model} into this form (internally just calls {@link Ext.form.Basic#loadRecord})
  252. * See also {@link Ext.form.Basic#trackResetOnLoad trackResetOnLoad}.
  253. * @param {Ext.data.Model} record The record to load
  254. * @return {Ext.form.Basic} The Ext.form.Basic attached to this FormPanel
  255. */
  256. loadRecord: function(record) {
  257. return this.getForm().loadRecord(record);
  258. },
  259. <span id='Ext-form-Panel-method-getRecord'> /**
  260. </span> * Returns the currently loaded Ext.data.Model instance if one was loaded via {@link #loadRecord}.
  261. * @return {Ext.data.Model} The loaded instance
  262. */
  263. getRecord: function() {
  264. return this.getForm().getRecord();
  265. },
  266. <span id='Ext-form-Panel-method-getValues'> /**
  267. </span> * Convenience function for fetching the current value of each field in the form. This is the same as calling
  268. * {@link Ext.form.Basic#getValues this.getForm().getValues()}.
  269. *
  270. * @inheritdoc Ext.form.Basic#getValues
  271. */
  272. getValues: function(asString, dirtyOnly, includeEmptyText, useDataValues) {
  273. return this.getForm().getValues(asString, dirtyOnly, includeEmptyText, useDataValues);
  274. },
  275. beforeDestroy: function() {
  276. this.stopPolling();
  277. this.form.destroy();
  278. this.callParent();
  279. },
  280. <span id='Ext-form-Panel-method-load'> /**
  281. </span> * This is a proxy for the underlying BasicForm's {@link Ext.form.Basic#load} call.
  282. * @param {Object} options The options to pass to the action (see {@link Ext.form.Basic#load} and
  283. * {@link Ext.form.Basic#doAction} for details)
  284. */
  285. load: function(options) {
  286. this.form.load(options);
  287. },
  288. <span id='Ext-form-Panel-method-submit'> /**
  289. </span> * This is a proxy for the underlying BasicForm's {@link Ext.form.Basic#submit} call.
  290. * @param {Object} options The options to pass to the action (see {@link Ext.form.Basic#submit} and
  291. * {@link Ext.form.Basic#doAction} for details)
  292. */
  293. submit: function(options) {
  294. this.form.submit(options);
  295. },
  296. <span id='Ext-form-Panel-method-startPolling'> /**
  297. </span> * Start an interval task to continuously poll all the fields in the form for changes in their
  298. * values. This is normally started automatically by setting the {@link #pollForChanges} config.
  299. * @param {Number} interval The interval in milliseconds at which the check should run.
  300. */
  301. startPolling: function(interval) {
  302. this.stopPolling();
  303. var task = new Ext.util.TaskRunner(interval);
  304. task.start({
  305. interval: 0,
  306. run: this.checkChange,
  307. scope: this
  308. });
  309. this.pollTask = task;
  310. },
  311. <span id='Ext-form-Panel-method-stopPolling'> /**
  312. </span> * Stop a running interval task that was started by {@link #startPolling}.
  313. */
  314. stopPolling: function() {
  315. var task = this.pollTask;
  316. if (task) {
  317. task.stopAll();
  318. delete this.pollTask;
  319. }
  320. },
  321. <span id='Ext-form-Panel-method-checkChange'> /**
  322. </span> * Forces each field within the form panel to
  323. * {@link Ext.form.field.Field#checkChange check if its value has changed}.
  324. */
  325. checkChange: function() {
  326. var fields = this.form.getFields().items,
  327. f,
  328. fLen = fields.length,
  329. field;
  330. for (f = 0; f &lt; fLen; f++) {
  331. fields[f].checkChange();
  332. }
  333. }
  334. });
  335. </pre>
  336. </body>
  337. </html>