+++ /dev/null
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"\r
- "http://www.w3.org/TR/html4/strict.dtd">\r
-<html>\r
-<head>\r
-\r
- <title>Form unit test</title>\r
- <style type="text/css">\r
- @import "../../../dojo/resources/dojo.css";\r
- @import "../css/dijitTests.css";\r
- </style>\r
- <script type="text/javascript" src="../../../dojo/dojo.js"\r
- djConfig="isDebug: true, parseOnLoad: true"></script>\r
- <script type="text/javascript" src="../_testCommon.js"></script>\r
-\r
- <script type="text/javascript">\r
- dojo.require("doh.runner");\r
- dojo.require("dojo.date");\r
- dojo.require("dijit.form.Form");\r
- dojo.require("dijit.layout.LayoutContainer");\r
- dojo.require("dijit.layout.ContentPane");\r
- dojo.require("dijit.form.ComboBox");\r
- dojo.require("dijit.form.CheckBox");\r
- dojo.require("dijit.form.DateTextBox");\r
- dojo.require("dijit.form.Button");\r
- dojo.require("dijit.form.MultiSelect");\r
- dojo.require("dijit.form.Textarea");\r
- dojo.require("dijit.form.SimpleTextarea");\r
- dojo.require("dijit.Editor");\r
-\r
- var obj;\r
- function getValues(){\r
- obj = dijit.byId('myForm').getValues();\r
- console.log("Object is: " + dojo.toJson(obj, true));\r
- }\r
- \r
- function setValues(){\r
- if(!obj){\r
- obj = {testF: 'testi'};\r
- }\r
- console.log("Object is: " + dojo.toJson(obj, true));\r
- dijit.byId('myForm').setValues(obj);\r
- }\r
-\r
- // make dojo.toJson() print dates correctly (this feels a bit dirty)\r
- Date.prototype.json = function(){ return dojo.date.stamp.toISOString(this, {selector: 'date'});};\r
-\r
- var d = dojo.date.stamp.fromISOString;\r
-\r
- // These are the values assigned to the widgets in the page's HTML\r
- var original = {\r
- foo: {bar: {baz: {quux: d("2007-12-30")} } },\r
- available: {from: d("2005-01-02"), to: d("2006-01-02")},\r
- plop: {combo: "one"},\r
- cb2: ["2", "3"],\r
- r2: "2",\r
- ms1: ["VA", "WA"],\r
- h1: "hidden",\r
- t1: "line 1\nline 2",\r
- st1: "simple line 1\nsimple line 2",\r
- richtext: "<h1>original</h1><p>This is the default content</p>",\r
- filename: ""\r
- };\r
-\r
- // we change the form to these values\r
- var changed = {\r
- foo: {bar: {baz: {quux: d("2005-01-01")} } },\r
- available: {from: d("2005-11-02"), to: d("2006-11-02")},\r
- plop: {combo: "three"},\r
- cb2: ["4"],\r
- r2: "1",\r
- ms1: ["FL", "CA"],\r
- h1: "still hidden",\r
- t1: "new line 1\nnew line 2",\r
- st1: "new simple line 1\nnew simple line 2",\r
- richtext: "<h1>changed</h1><p>This is the changed content set by setValues</p>",\r
- filename: ""\r
- };\r
- // we reset the form to these values\r
- var reset = {\r
- foo: {bar: {baz: {quux: d("2007-12-30")} } },\r
- available: {from: d("2005-01-02"), to: d("2006-01-02")},\r
- plop: {combo: "one"},\r
- cb2: ["2", "3"],\r
- r2: "2",\r
- ms1: ["VA", "WA"],\r
- h1: "hidden",\r
- t1: "line 1\nline 2",\r
- st1: "simple line 1\nsimple line 2",\r
- richtext: "<h1>changed</h1><p>This is the changed content set by setValues</p>", // not a form element, so not reset\r
- filename: ""\r
- };\r
-\r
- dojo.addOnLoad(function(){\r
- doh.register("dijit.form.Form",\r
- [\r
- function getValues(){\r
- var values = dijit.byId("myForm").getValues();\r
- \r
- // FF3 sticks in some tabs and newlines that mess up the equality check\r
- // Need better way to compare two HTML trees but for now do this.\r
- values.richtext = values.richtext.replace(/[\n\t]/, "", "g");\r
-\r
- doh.is( dojo.toJson(original), dojo.toJson(values) );\r
- },\r
- function setValues(){\r
- dijit.byId("myForm").setValues(changed);\r
- doh.is( dojo.toJson(changed), dojo.toJson(dijit.byId("myForm").getValues()) );\r
- },\r
- function nameAttributeSurvived(){ // ticket:4753\r
- var radios = dojo.query(".RadioButton", dijit.byId("radio-cells")).forEach(\r
- function(r) {\r
- doh.is( r.inputNode.name, "r2" );\r
- });\r
- \r
- },\r
- function resetTest(){\r
- dijit.byId("myForm").reset();\r
- doh.is( dojo.toJson(reset), dojo.toJson(dijit.byId("myForm").getValues()) );\r
- }\r
- ]\r
- );\r
- doh.run();\r
- });\r
-\r
- </script>\r
-</head>\r
-<body>\r
- <h1>Form Widget Unit Test</h1>\r
- <p>\r
- The form widget takes data in a form and serializes/deserializes it, so\r
- it can be submitted as a JSON string of nested objects.\r
- </p>\r
- <div style="color:red">Currently only widgets are supported, not raw elements.</div>\r
- <!-- to test form submission, you'll need to create an action handler similar to\r
- http://www.utexas.edu/teamweb/cgi-bin/generic.cgi \r
- http://www.tipjar.com/cgi-bin/test -->\r
- <form dojoType="dijit.form.Form" id="myForm" \r
- encType="multipart/form-data" action="" method="">\r
- <script type="dojo/method" event="onReset">\r
- return confirm('Press OK to reset widget values');\r
- </script>\r
- <script type="dojo/method" event="onSubmit">\r
- console.debug('Attempting to submit form w/values:\n',\r
- dojo.toJson(this.getValues(),true)\r
- );\r
- if(this.validate()){\r
- return confirm('Form is valid, press OK to submit');\r
- }else{\r
- alert('Form contains invalid data. Please correct first');\r
- return false;\r
- }\r
- return true;\r
- </script>\r
- <script type="dojo/method" event="onReset">\r
- return confirm('reset Form?');\r
- </script>\r
- <p>Just HTML text</p>\r
- <table style="border: 1px solid #9f9f9f;" cellspacing="10">\r
- <thead>\r
- <tr>\r
- <th>Description</th>\r
- <th>Name</th>\r
- <th>Form node/widget</th>\r
- </tr>\r
- </thead>\r
- <tbody>\r
- <!--\r
- <tr><td>text</td><td>testF</td><td><input type="text" name="testF" value="bar1" /></td></tr>\r
- <tr><td>password</td><td>passwordF</td><td><input type="password" name="passwordF" value="bar4" /></td></tr>\r
- <tr><td>hidden</td><td>hiddenF</td><td><input type="hidden" name="hiddenF" value="bar4" /></td></tr>\r
- <tr><td>select</td><td>plop.noncombo</td><td>\r
- <div class="group">\r
- <select name="plop.noncombo">\r
- <option value="1">one</option>\r
- <option value="2">two</option>\r
- <option value="3">three</option>\r
- </select>\r
- </div>\r
-\r
- </td></tr>\r
- -->\r
-\r
- <tr>\r
- <td>DateTextBox inside contentpane</td>\r
- <td>foo.bar.baz.quux</td>\r
- <td>\r
- <div dojoType="dijit.layout.ContentPane">\r
- <input type="text" name="foo.bar.baz.quux" dojoType="dijit.form.DateTextBox" value="2007-12-30" />\r
- </div>\r
- </td>\r
- </tr>\r
- <tr>\r
- <td>Layoutcontainer</td>\r
- <td>\r
- <div dojoType="dijit.layout.LayoutContainer"></div>\r
- </td>\r
- </tr>\r
- <tr>\r
- <td>DateTextBox 1</td>\r
- <td>available.from</td>\r
- <td>\r
- <input type="text" name="available.from" dojoType="dijit.form.DateTextBox" value="2005-01-02" />\r
- </td>\r
- </tr>\r
- <tr>\r
- <td>DateTextBox 2</td>\r
- <td>available.to</td>\r
- <td>\r
- <input type="text" name="available.to" dojoType="dijit.form.DateTextBox" value="2006-01-02" />\r
- </td>\r
- </tr>\r
- <tr>\r
- <td>ComboBox</td>\r
- <td>plop.combo</td>\r
- <td>\r
- <select name="plop.combo" dojoType="dijit.form.ComboBox">\r
- <option value="one">one</option>\r
- <option value="two">two</option>\r
- <option value="three">three</option>\r
- </select>\r
- </td>\r
- </tr>\r
-\r
- <!--\r
- <tr>\r
- <td>textarea</td>\r
- <td>myTextArea</td>\r
- <td>\r
- <textarea name="myTextArea">\r
- text text text """ \\\/\r
- </textarea>\r
- </td>\r
- </tr>\r
- -->\r
-\r
- <!--\r
- <tr>\r
- <td>CheckBox</td>\r
- <td>cb1</td>\r
- <td>\r
- <input type="checkbox" name="cb1" value="1" /> 1\r
- <input type="checkbox" name="cb1" value="2" checked="checked" /> 2\r
- <input type="checkbox" name="cb1" value="3" checked="checked" /> 3\r
- <input type="checkbox" name="cb1" value="4" /> 4\r
- </td>\r
- </tr>\r
- -->\r
-\r
- <tr>\r
- <td>CheckBox widget</td>\r
- <td>cb2</td>\r
- <td>\r
- <input dojoType="dijit.form.CheckBox" type="checkbox" name="cb2" value="1" /> 1\r
- <input dojoType="dijit.form.CheckBox" type="checkbox" name="cb2" value="2" checked="checked" /> 2\r
- <input dojoType="dijit.form.CheckBox" type="checkbox" name="cb2" value="3" checked="checked" /> 3\r
- <input dojoType="dijit.form.CheckBox" type="checkbox" name="cb2" value="4" /> 4\r
- </td>\r
- </tr>\r
-\r
- <!--\r
- <tr>\r
- <td>radio</td>\r
- <td>r1</td>\r
- <td>\r
- <input type="radio" name="r1" value="1" /> 1\r
- <input type="radio" name="r1" value="2" /> 2\r
- <input type="radio" name="r1" value="3" /> 3\r
- <input type="radio" name="r1" value="4" /> 4\r
- </td>\r
- </tr>\r
- -->\r
-\r
- <tr>\r
- <td>Radio widget</td><td>r2</td>\r
- <td id="radio-cells">\r
- <input dojoType="dijit.form.RadioButton" type="radio" name="r2" value="1" /> 1\r
- <input dojoType="dijit.form.RadioButton" type="radio" name="r2" value="2" checked="checked" /> 2\r
- <input dojoType="dijit.form.RadioButton" type="radio" name="r2" value="3"/> 3\r
- <input dojoType="dijit.form.RadioButton" type="radio" name="r2" value="4" /> 4\r
- </td>\r
- </tr>\r
-\r
- <tr>\r
- <td>Multi-select</td><td>ms1</td>\r
- <td>\r
- <select id="ms1" multiple="true" name="ms1"\r
- dojoType="dijit.form.MultiSelect"\r
- style="height:100px; width:175px; border:5px solid #ededed;">\r
-\r
- <option value="TN">Tennessee</option>\r
- <option value="VA" selected="true">Virginia</option>\r
- <option value="WA" selected="true">Washington</option>\r
- <option value="FL">Florida</option>\r
- <option value="CA">California</option>\r
-\r
- </select>\r
- </td>\r
- </tr>\r
-\r
- <tr>\r
- <td>Hidden input</td>\r
- <td>h1</td>\r
- <td>\r
- <input id="h1" name="h1" dojoType="dijit.form.TextBox" type="hidden" value="hidden">\r
- </td>\r
- </tr>\r
-\r
- <tr>\r
- <td>Auto-sizing textarea</td>\r
- <td>t1</td>\r
- <td>\r
- <textarea id="t1" name="t1" \r
- dojoType="dijit.form.Textarea">line 1\r
-line 2</textarea>\r
- </td>\r
- </tr>\r
-\r
- <tr>\r
- <td>Fixed size textarea</td>\r
- <td>st1</td>\r
- <td>\r
- <textarea id="st1" name="st1" dojoType="dijit.form.SimpleTextarea" rows=5 cols=50>\r
-simple line 1\r
-simple line 2</textarea>\r
- </td>\r
- </tr>\r
-\r
- <tr>\r
- <td>Editor widget</td>\r
- <td>richtext</td>\r
- <td>\r
- <textarea dojoType="dijit.Editor" name="richtext" pluginsConfig="[{items:['bold','italic']}]"><h1>original</h1><p>This is the default content</p></textarea>\r
- </td>\r
- </tr>\r
-\r
- <tr>\r
- <td>File upload</td>\r
- <td>filename</td>\r
- <td>\r
- <input dojoType="dijit.form.TextBox" name="filename" type="file">\r
- </td>\r
- </tr>\r
- </tbody>\r
- </table>\r
-\r
- <button dojoType=dijit.form.Button onClick="getValues();">Get Values from form!</button>\r
- <button dojoType=dijit.form.Button onClick="setValues();">Set Values to form!</button>\r
- <button dojoType=dijit.form.Button type="submit">Submit</button>\r
- <button dojoType=dijit.form.Button type="reset">Reset</button>\r
- </form>\r
-\r
-\r
-</body>\r
-</html>\r