1791a125f385fa021aa043231fdd442252f1bc10.svn-base 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  2. "http://www.w3.org/TR/html4/strict.dtd">
  3. <html>
  4. <head>
  5. <title>Form unit test</title>
  6. <style type="text/css">
  7. @import "../../../dojo/resources/dojo.css";
  8. @import "../css/dijitTests.css";
  9. </style>
  10. <script type="text/javascript" src="../../../dojo/dojo.js"
  11. djConfig="isDebug: true, parseOnLoad: true"></script>
  12. <script type="text/javascript" src="../_testCommon.js"></script>
  13. <script type="text/javascript">
  14. dojo.require("doh.runner");
  15. dojo.require("dojo.date");
  16. dojo.require("dijit.form.Form");
  17. dojo.require("dijit.layout.LayoutContainer");
  18. dojo.require("dijit.layout.ContentPane");
  19. dojo.require("dijit.form.ComboBox");
  20. dojo.require("dijit.form.CheckBox");
  21. dojo.require("dijit.form.DateTextBox");
  22. dojo.require("dijit.form.Button");
  23. dojo.require("dijit.Editor");
  24. var obj;
  25. function getValues(){
  26. obj = dijit.byId('myForm').getValues();
  27. console.log("Object is: " + dojo.toJson(obj, true));
  28. }
  29. function setValues(){
  30. if(!obj){
  31. obj = {testF: 'testi'};
  32. }
  33. console.log("Object is: " + dojo.toJson(obj, true));
  34. dijit.byId('myForm').setValues(obj);
  35. }
  36. // make dojo.toJson() print dates correctly (this feels a bit dirty)
  37. Date.prototype.json = function(){ return dojo.date.stamp.toISOString(this, {selector: 'date'});};
  38. var d = dojo.date.stamp.fromISOString;
  39. // These are the values assigned to the widgets in the page's HTML
  40. var original = {
  41. foo: {bar: {baz: {quux: d("2007-12-30")} } },
  42. available: {from: d("2005-01-02"), to: d("2006-01-02")},
  43. plop: {combo: "one"},
  44. cb2: ["2", "3"],
  45. r2: "2",
  46. richtext: "<h1>original</h1><p>This is the default content</p>"
  47. };
  48. // we reset the form to these values
  49. var changed = {
  50. foo: {bar: {baz: {quux: d("2005-01-01")} } },
  51. available: {from: d("2005-11-02"), to: d("2006-11-02")},
  52. plop: {combo: "three"},
  53. cb2: ["4"],
  54. r2: "1",
  55. richtext: "<h1>changed</h1><p>This is the changed content set by setValues</p>"
  56. };
  57. dojo.addOnLoad(function(){
  58. doh.register("dijit.form.Form",
  59. [
  60. function getValues(){
  61. doh.is( dojo.toJson(original), dojo.toJson(dijit.byId("myForm").getValues()) );
  62. },
  63. function setValues(){
  64. dijit.byId("myForm").setValues(changed);
  65. doh.is( dojo.toJson(changed), dojo.toJson(dijit.byId("myForm").getValues()) );
  66. },
  67. function nameAttributeSurvived(){ // ticket:4753
  68. var radios = dojo.query(".RadioButton", dijit.byId("radio-cells")).forEach(
  69. function(r) {
  70. doh.is( r.inputNode.name, "r2" );
  71. });
  72. }
  73. ]
  74. );
  75. doh.run();
  76. });
  77. </script>
  78. </head>
  79. <body>
  80. <h1>Form Widget Unit Test</h1>
  81. <p>
  82. The form widget takes data in a form and serializes/deserializes it,
  83. so it can be submitted as a JSON string of nested objects.
  84. </p>
  85. <div style="color:red">Currently only widgets are supported, not raw elements.</div>
  86. <form dojoType="dijit.form.Form" id="myForm" action="showPost.php" execute="alert('Execute form w/values:\n'+dojo.toJson(arguments[0],true));">
  87. <p>Just HTML text</p>
  88. <table border=2>
  89. <tr><th>Description</th><th>Name</th><th>Form node/widget</th></tr>
  90. <!--
  91. <tr><td>text</td><td>testF</td><td><input type="text" name="testF" value="bar1" /></td></tr>
  92. <tr><td>password</td><td>passwordF</td><td><input type="password" name="passwordF" value="bar4" /></td></tr>
  93. <tr><td>hidden</td><td>hiddenF</td><td><input type="hidden" name="hiddenF" value="bar4" /></td></tr>
  94. <tr><td>select</td><td>plop.noncombo</td><td>
  95. <div class="group">
  96. <select name="plop.noncombo">
  97. <option value="1">one</option>
  98. <option value="2">two</option>
  99. <option value="3">three</option>
  100. </select>
  101. </div>
  102. </td></tr>
  103. -->
  104. <tr><td>DateTextBox inside contentpane</td><td>foo.bar.baz.quux</td><td>
  105. <div dojoType="dijit.layout.ContentPane">
  106. <input type="text" name="foo.bar.baz.quux" dojoType="dijit.form.DateTextBox" value="2007-12-30" />
  107. </div>
  108. </td></tr>
  109. <tr><td>Layoutcontainer</td><td>
  110. <div dojoType="dijit.layout.LayoutContainer">
  111. </div>
  112. </td></tr>
  113. <tr>
  114. <td>DateTextBox 1</td><td>available.from</td><td>
  115. <input type="text" name="available.from" dojoType="dijit.form.DateTextBox" value="2005-01-02" />
  116. </td>
  117. </tr>
  118. <tr>
  119. <td>DateTextBox 2</td><td>available.to</td><td>
  120. <input type="text" name="available.to" dojoType="dijit.form.DateTextBox" value="2006-01-02" />
  121. </td>
  122. </tr>
  123. <tr><td>ComboBox</td><td>plop.combo</td>
  124. <td>
  125. <select name="plop.combo" dojoType="dijit.form.ComboBox">
  126. <option value="one">one</option>
  127. <option value="two">two</option>
  128. <option value="three">three</option>
  129. </select>
  130. </td></tr>
  131. <!--
  132. <tr>
  133. <td>textarea</td><td>myTextArea</td>
  134. <td>
  135. <textarea name="myTextArea">
  136. text text text """ \\\/
  137. </textarea>
  138. </td>
  139. </tr>
  140. -->
  141. <!--
  142. <tr>
  143. <td>CheckBox</td><td>cb1</td>
  144. <td>
  145. <input type="checkbox" name="cb1" value="1" /> 1
  146. <input type="checkbox" name="cb1" value="2" checked="checked" /> 2
  147. <input type="checkbox" name="cb1" value="3" checked="checked" /> 3
  148. <input type="checkbox" name="cb1" value="4" /> 4
  149. </td>
  150. </tr>
  151. -->
  152. <tr>
  153. <td>CheckBox widget</td><td>cb2</td>
  154. <td>
  155. <input dojoType="dijit.form.CheckBox" type="checkbox" name="cb2" value="1" /> 1
  156. <input dojoType="dijit.form.CheckBox" type="checkbox" name="cb2" value="2" checked="checked" /> 2
  157. <input dojoType="dijit.form.CheckBox" type="checkbox" name="cb2" value="3" checked="checked" /> 3
  158. <input dojoType="dijit.form.CheckBox" type="checkbox" name="cb2" value="4" /> 4
  159. </td>
  160. </tr>
  161. <!--
  162. <tr>
  163. <td>radio</td><td>r1</td>
  164. <td>
  165. <input type="radio" name="r1" value="1" /> 1
  166. <input type="radio" name="r1" value="2" /> 2
  167. <input type="radio" name="r1" value="3" /> 3
  168. <input type="radio" name="r1" value="4" /> 4
  169. </td>
  170. </tr>
  171. -->
  172. <tr>
  173. <td>Radio widget</td><td>r2</td>
  174. <td id="radio-cells">
  175. <input dojoType="dijit.form.RadioButton" type="radio" name="r2" value="1" /> 1
  176. <input dojoType="dijit.form.RadioButton" type="radio" name="r2" value="2" checked="checked" /> 2
  177. <input dojoType="dijit.form.RadioButton" type="radio" name="r2" value="3"/> 3
  178. <input dojoType="dijit.form.RadioButton" type="radio" name="r2" value="4" /> 4
  179. </td>
  180. </tr>
  181. <tr>
  182. <td>Editor widget</td><td>richtext</td>
  183. <td>
  184. <textarea dojoType="dijit.Editor" name="richtext" pluginsConfig="[{items:['bold','italic']}]"/><h1>original</h1><p>This is the default content</p></textarea>
  185. </td>
  186. </tr>
  187. </table>
  188. <button dojoType=dijit.form.Button onClick="getValues();">Get Values from form!</button>
  189. <button dojoType=dijit.form.Button onClick="setValues();">Set Values to form!</button>
  190. <button dojoType=dijit.form.Button type=submit>Submit</button>
  191. </form>
  192. </body>
  193. </html>