Form.js.uncompressed.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. define("dijit/form/Form", [
  2. "dojo/_base/declare", // declare
  3. "dojo/dom-attr", // domAttr.set
  4. "dojo/_base/event", // event.stop
  5. "dojo/_base/kernel", // kernel.deprecated
  6. "dojo/sniff", // has("ie")
  7. "../_Widget",
  8. "../_TemplatedMixin",
  9. "./_FormMixin",
  10. "../layout/_ContentPaneResizeMixin"
  11. ], function(declare, domAttr, event, kernel, has, _Widget, _TemplatedMixin, _FormMixin, _ContentPaneResizeMixin){
  12. // module:
  13. // dijit/form/Form
  14. return declare("dijit.form.Form", [_Widget, _TemplatedMixin, _FormMixin, _ContentPaneResizeMixin], {
  15. // summary:
  16. // Widget corresponding to HTML form tag, for validation and serialization
  17. //
  18. // example:
  19. // | <form data-dojo-type="dijit/form/Form" id="myForm">
  20. // | Name: <input type="text" name="name" />
  21. // | </form>
  22. // | myObj = {name: "John Doe"};
  23. // | dijit.byId('myForm').set('value', myObj);
  24. // |
  25. // | myObj=dijit.byId('myForm').get('value');
  26. // HTML <FORM> attributes
  27. // name: String?
  28. // Name of form for scripting.
  29. name: "",
  30. // action: String?
  31. // Server-side form handler.
  32. action: "",
  33. // method: String?
  34. // HTTP method used to submit the form, either "GET" or "POST".
  35. method: "",
  36. // encType: String?
  37. // Encoding type for the form, ex: application/x-www-form-urlencoded.
  38. encType: "",
  39. // accept-charset: String?
  40. // List of supported charsets.
  41. "accept-charset": "",
  42. // accept: String?
  43. // List of MIME types for file upload.
  44. accept: "",
  45. // target: String?
  46. // Target frame for the document to be opened in.
  47. target: "",
  48. templateString: "<form data-dojo-attach-point='containerNode' data-dojo-attach-event='onreset:_onReset,onsubmit:_onSubmit' ${!nameAttrSetting}></form>",
  49. postMixInProperties: function(){
  50. // Setup name=foo string to be referenced from the template (but only if a name has been specified)
  51. // Unfortunately we can't use _setNameAttr to set the name due to IE limitations, see #8660
  52. this.nameAttrSetting = this.name ? ("name='" + this.name + "'") : "";
  53. this.inherited(arguments);
  54. },
  55. execute: function(/*Object*/ /*===== formContents =====*/){
  56. // summary:
  57. // Deprecated: use submit()
  58. // tags:
  59. // deprecated
  60. },
  61. onExecute: function(){
  62. // summary:
  63. // Deprecated: use onSubmit()
  64. // tags:
  65. // deprecated
  66. },
  67. _setEncTypeAttr: function(/*String*/ value){
  68. this.encType = value;
  69. domAttr.set(this.domNode, "encType", value);
  70. if(has("ie")){ this.domNode.encoding = value; }
  71. },
  72. reset: function(/*Event?*/ e){
  73. // summary:
  74. // restores all widget values back to their init values,
  75. // calls onReset() which can cancel the reset by returning false
  76. // create fake event so we can know if preventDefault() is called
  77. var faux = {
  78. returnValue: true, // the IE way
  79. preventDefault: function(){ // not IE
  80. this.returnValue = false;
  81. },
  82. stopPropagation: function(){},
  83. currentTarget: e ? e.target : this.domNode,
  84. target: e ? e.target : this.domNode
  85. };
  86. // if return value is not exactly false, and haven't called preventDefault(), then reset
  87. if(!(this.onReset(faux) === false) && faux.returnValue){
  88. this.inherited(arguments, []);
  89. }
  90. },
  91. onReset: function(/*Event?*/ /*===== e =====*/){
  92. // summary:
  93. // Callback when user resets the form. This method is intended
  94. // to be over-ridden. When the `reset` method is called
  95. // programmatically, the return value from `onReset` is used
  96. // to compute whether or not resetting should proceed
  97. // tags:
  98. // callback
  99. return true; // Boolean
  100. },
  101. _onReset: function(e){
  102. this.reset(e);
  103. event.stop(e);
  104. return false;
  105. },
  106. _onSubmit: function(e){
  107. var fp = this.constructor.prototype;
  108. // TODO: remove this if statement beginning with 2.0
  109. if(this.execute != fp.execute || this.onExecute != fp.onExecute){
  110. kernel.deprecated("dijit.form.Form:execute()/onExecute() are deprecated. Use onSubmit() instead.", "", "2.0");
  111. this.onExecute();
  112. this.execute(this.getValues());
  113. }
  114. if(this.onSubmit(e) === false){ // only exactly false stops submit
  115. event.stop(e);
  116. }
  117. },
  118. onSubmit: function(/*Event?*/ /*===== e =====*/){
  119. // summary:
  120. // Callback when user submits the form.
  121. // description:
  122. // This method is intended to be over-ridden, but by default it checks and
  123. // returns the validity of form elements. When the `submit`
  124. // method is called programmatically, the return value from
  125. // `onSubmit` is used to compute whether or not submission
  126. // should proceed
  127. // tags:
  128. // extension
  129. return this.isValid(); // Boolean
  130. },
  131. submit: function(){
  132. // summary:
  133. // programmatically submit form if and only if the `onSubmit` returns true
  134. if(!(this.onSubmit() === false)){
  135. this.containerNode.submit();
  136. }
  137. }
  138. });
  139. });