PageRenderTime 26ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/public/ext-4.0.0/docs/source/Panel.html

https://github.com/marekjs/Shacser
HTML | 318 lines | 271 code | 47 blank | 0 comment | 0 complexity | 8e36ece5b7e89a70252b5bb4e85f7e74 MD5 | raw file
  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.Panel-method-constructor'><span id='Ext-form.Panel'>/**
  2. </span></span> * @class Ext.form.Panel
  3. * @extends Ext.panel.Panel
  4. FormPanel provides a standard container for forms. It is essentially a standard {@link Ext.panel.Panel} which
  5. automatically creates a {@link Ext.form.Basic BasicForm} for managing any {@link Ext.form.field.Field}
  6. objects that are added as descendants of the panel. It also includes conveniences for configuring and
  7. working with the BasicForm and the collection of Fields.
  8. __Layout__
  9. By default, FormPanel is configured with `{@link Ext.layout.container.Anchor layout:'anchor'}` for
  10. the layout of its immediate child items. This can be changed to any of the supported container layouts.
  11. The layout of sub-containers is configured in {@link Ext.container.Container#layout the standard way}.
  12. __BasicForm__
  13. Although **not listed** as configuration options of FormPanel, the FormPanel class accepts all
  14. of the config options supported by the {@link Ext.form.Basic} class, and will pass them along to
  15. the internal BasicForm when it is created.
  16. **Note**: If subclassing FormPanel, any configuration options for the BasicForm must be applied to
  17. the `initialConfig` property of the FormPanel. Applying {@link Ext.form.Basic BasicForm}
  18. configuration settings to `this` will *not* affect the BasicForm's configuration.
  19. The following events fired by the BasicForm will be re-fired by the FormPanel and can therefore be
  20. listened for on the FormPanel itself:
  21. - {@link Ext.form.Basic#beforeaction beforeaction}
  22. - {@link Ext.form.Basic#actionfailed actionfailed}
  23. - {@link Ext.form.Basic#actioncomplete actioncomplete}
  24. - {@link Ext.form.Basic#validitychange validitychange}
  25. - {@link Ext.form.Basic#dirtychange dirtychange}
  26. __Field Defaults__
  27. The {@link #fieldDefaults} config option conveniently allows centralized configuration of default values
  28. for all fields added as descendants of the FormPanel. Any config option recognized by implementations
  29. of {@link Ext.form.Labelable} may be included in this object. See the {@link #fieldDefaults} documentation
  30. for details of how the defaults are applied.
  31. __Form Validation__
  32. With the default configuration, form fields are validated on-the-fly while the user edits their values.
  33. This can be controlled on a per-field basis (or via the {@link #fieldDefaults} config) with the field
  34. config properties {@link Ext.form.field.Field#validateOnChange} and {@link Ext.form.field.Base#checkChangeEvents},
  35. and the FormPanel's config properties {@link #pollForChanges} and {@link #pollInterval}.
  36. Any component within the FormPanel can be configured with `formBind: true`. This will cause that
  37. component to be automatically disabled when the form is invalid, and enabled when it is valid. This is most
  38. commonly used for Button components to prevent submitting the form in an invalid state, but can be used on
  39. any component type.
  40. For more information on form validation see the following:
  41. - {@link Ext.form.field.Field#validateOnChange}
  42. - {@link #pollForChanges} and {@link #pollInterval}
  43. - {@link Ext.form.field.VTypes}
  44. - {@link Ext.form.Basic#doAction BasicForm.doAction clientValidation notes}
  45. __Form Submission__
  46. By default, Ext Forms are submitted through Ajax, using {@link Ext.form.action.Action}. See the documentation for
  47. {@link Ext.form.Basic} for details.
  48. {@img Ext.form.FormPanel/Ext.form.FormPanel.png Ext.form.FormPanel FormPanel component}
  49. __Example usage:__
  50. Ext.create('Ext.form.Panel', {
  51. title: 'Simple Form',
  52. bodyPadding: 5,
  53. width: 350,
  54. // The form will submit an AJAX request to this URL when submitted
  55. url: 'save-form.php',
  56. // Fields will be arranged vertically, stretched to full width
  57. layout: 'anchor',
  58. defaults: {
  59. anchor: '100%'
  60. },
  61. // The fields
  62. defaultType: 'textfield',
  63. items: [{
  64. fieldLabel: 'First Name',
  65. name: 'first',
  66. allowBlank: false
  67. },{
  68. fieldLabel: 'Last Name',
  69. name: 'last',
  70. allowBlank: false
  71. }],
  72. // Reset and Submit buttons
  73. buttons: [{
  74. text: 'Reset',
  75. handler: function() {
  76. this.up('form').getForm().reset();
  77. }
  78. }, {
  79. text: 'Submit',
  80. formBind: true, //only enabled once the form is valid
  81. disabled: true,
  82. handler: function() {
  83. var form = this.up('form').getForm();
  84. if (form.isValid()) {
  85. form.submit({
  86. success: function(form, action) {
  87. Ext.Msg.alert('Success', action.result.msg);
  88. },
  89. failure: function(form, action) {
  90. Ext.Msg.alert('Failed', action.result.msg);
  91. }
  92. });
  93. }
  94. }
  95. }],
  96. renderTo: Ext.getBody()
  97. });
  98. * @constructor
  99. * @param {Object} config Configuration options
  100. * @xtype form
  101. *
  102. * @markdown
  103. * @docauthor Jason Johnston &lt;jason@sencha.com&gt;
  104. */
  105. Ext.define('Ext.form.Panel', {
  106. extend:'Ext.panel.Panel',
  107. mixins: {
  108. fieldAncestor: 'Ext.form.FieldAncestor'
  109. },
  110. alias: 'widget.form',
  111. alternateClassName: ['Ext.FormPanel', 'Ext.form.FormPanel'],
  112. requires: ['Ext.form.Basic', 'Ext.util.TaskRunner'],
  113. <span id='Ext-form.Panel-cfg-pollForChanges'> /**
  114. </span> * @cfg {Boolean} pollForChanges
  115. * If set to &lt;tt&gt;true&lt;/tt&gt;, sets up an interval task (using the {@link #pollInterval}) in which the
  116. * panel's fields are repeatedly checked for changes in their values. This is in addition to the normal detection
  117. * each field does on its own input element, and is not needed in most cases. It does, however, provide a
  118. * means to absolutely guarantee detection of all changes including some edge cases in some browsers which
  119. * do not fire native events. Defaults to &lt;tt&gt;false&lt;/tt&gt;.
  120. */
  121. <span id='Ext-form.Panel-cfg-pollInterval'> /**
  122. </span> * @cfg {Number} pollInterval
  123. * Interval in milliseconds at which the form's fields are checked for value changes. Only used if
  124. * the {@link #pollForChanges} option is set to &lt;tt&gt;true&lt;/tt&gt;. Defaults to 500 milliseconds.
  125. */
  126. <span id='Ext-form.Panel-cfg-layout'> /**
  127. </span> * @cfg {String} layout The {@link Ext.container.Container#layout} for the form panel's immediate child items.
  128. * Defaults to &lt;tt&gt;'anchor'&lt;/tt&gt;.
  129. */
  130. layout: 'anchor',
  131. ariaRole: 'form',
  132. initComponent: function() {
  133. var me = this;
  134. if (me.frame) {
  135. me.border = false;
  136. }
  137. me.initFieldAncestor();
  138. me.callParent();
  139. me.relayEvents(me.form, [
  140. 'beforeaction',
  141. 'actionfailed',
  142. 'actioncomplete',
  143. 'validitychange',
  144. 'dirtychange'
  145. ]);
  146. // Start polling if configured
  147. if (me.pollForChanges) {
  148. me.startPolling(me.pollInterval || 500);
  149. }
  150. },
  151. initItems: function() {
  152. // Create the BasicForm
  153. var me = this;
  154. me.form = me.createForm();
  155. me.callParent();
  156. me.form.initialize();
  157. },
  158. <span id='Ext-form.Panel-method-createForm'> /**
  159. </span> * @private
  160. */
  161. createForm: function() {
  162. return Ext.create('Ext.form.Basic', this, Ext.applyIf({listeners: {}}, this.initialConfig));
  163. },
  164. <span id='Ext-form.Panel-method-getForm'> /**
  165. </span> * Provides access to the {@link Ext.form.Basic Form} which this Panel contains.
  166. * @return {Ext.form.Basic} The {@link Ext.form.Basic Form} which this Panel contains.
  167. */
  168. getForm: function() {
  169. return this.form;
  170. },
  171. <span id='Ext-form.Panel-method-loadRecord'> /**
  172. </span> * Loads an {@link Ext.data.Model} into this form (internally just calls {@link Ext.form.Basic#loadRecord})
  173. * See also {@link #trackResetOnLoad}.
  174. * @param {Ext.data.Model} record The record to load
  175. * @return {Ext.form.Basic} The Ext.form.Basic attached to this FormPanel
  176. */
  177. loadRecord: function(record) {
  178. return this.getForm().loadRecord(record);
  179. },
  180. <span id='Ext-form.Panel-method-getRecord'> /**
  181. </span> * Returns the currently loaded Ext.data.Model instance if one was loaded via {@link #loadRecord}.
  182. * @return {Ext.data.Model} The loaded instance
  183. */
  184. getRecord: function() {
  185. return this.getForm().getRecord();
  186. },
  187. <span id='Ext-form.Panel-method-getValues'> /**
  188. </span> * Convenience function for fetching the current value of each field in the form. This is the same as calling
  189. * {@link Ext.form.Basic#getValues this.getForm().getValues()}
  190. * @return {Object} The current form field values, keyed by field name
  191. */
  192. getValues: function() {
  193. return this.getForm().getValues();
  194. },
  195. beforeDestroy: function() {
  196. this.stopPolling();
  197. this.form.destroy();
  198. this.callParent();
  199. },
  200. <span id='Ext-form.Panel-method-load'> /**
  201. </span> * This is a proxy for the underlying BasicForm's {@link Ext.form.Basic#load} call.
  202. * @param {Object} options The options to pass to the action (see {@link Ext.form.Basic#load} and
  203. * {@link Ext.form.Basic#doAction} for details)
  204. */
  205. load: function(options) {
  206. this.form.load(options);
  207. },
  208. <span id='Ext-form.Panel-method-submit'> /**
  209. </span> * This is a proxy for the underlying BasicForm's {@link Ext.form.Basic#submit} call.
  210. * @param {Object} options The options to pass to the action (see {@link Ext.form.Basic#submit} and
  211. * {@link Ext.form.Basic#doAction} for details)
  212. */
  213. submit: function(options) {
  214. this.form.submit(options);
  215. },
  216. /*
  217. * Inherit docs, not using onDisable because it only gets fired
  218. * when the component is rendered.
  219. */
  220. disable: function(silent) {
  221. this.callParent(arguments);
  222. this.form.getFields().each(function(field) {
  223. field.disable();
  224. });
  225. },
  226. /*
  227. * Inherit docs, not using onEnable because it only gets fired
  228. * when the component is rendered.
  229. */
  230. enable: function(silent) {
  231. this.callParent(arguments);
  232. this.form.getFields().each(function(field) {
  233. field.enable();
  234. });
  235. },
  236. <span id='Ext-form.Panel-method-startPolling'> /**
  237. </span> * Start an interval task to continuously poll all the fields in the form for changes in their
  238. * values. This is normally started automatically by setting the {@link #pollForChanges} config.
  239. * @param {Number} interval The interval in milliseconds at which the check should run.
  240. */
  241. startPolling: function(interval) {
  242. this.stopPolling();
  243. var task = Ext.create('Ext.util.TaskRunner', interval);
  244. task.start({
  245. interval: 0,
  246. run: this.checkChange,
  247. scope: this
  248. });
  249. this.pollTask = task;
  250. },
  251. <span id='Ext-form.Panel-method-stopPolling'> /**
  252. </span> * Stop a running interval task that was started by {@link #startPolling}.
  253. */
  254. stopPolling: function() {
  255. var task = this.pollTask;
  256. if (task) {
  257. task.stopAll();
  258. delete this.pollTask;
  259. }
  260. },
  261. <span id='Ext-form.Panel-method-checkChange'> /**
  262. </span> * Forces each field within the form panel to
  263. * {@link Ext.form.field.Field#checkChange check if its value has changed}.
  264. */
  265. checkChange: function() {
  266. this.form.getFields().each(function(field) {
  267. field.checkChange();
  268. });
  269. }
  270. });
  271. </pre></pre></body></html>