New file |
0,0 → 1,217 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
"http://www.w3.org/TR/html4/strict.dtd"> |
<html> |
<head> |
|
<title>Form unit test</title> |
<style type="text/css"> |
@import "../../../dojo/resources/dojo.css"; |
@import "../css/dijitTests.css"; |
</style> |
<script type="text/javascript" src="../../../dojo/dojo.js" |
djConfig="isDebug: true, parseOnLoad: true"></script> |
<script type="text/javascript" src="../_testCommon.js"></script> |
|
<script type="text/javascript"> |
dojo.require("doh.runner"); |
dojo.require("dojo.date"); |
dojo.require("dijit.form.Form"); |
dojo.require("dijit.layout.LayoutContainer"); |
dojo.require("dijit.layout.ContentPane"); |
dojo.require("dijit.form.ComboBox"); |
dojo.require("dijit.form.CheckBox"); |
dojo.require("dijit.form.DateTextBox"); |
dojo.require("dijit.form.Button"); |
dojo.require("dijit.Editor"); |
|
var obj; |
function getValues(){ |
obj = dijit.byId('myForm').getValues(); |
console.log("Object is: " + dojo.toJson(obj, true)); |
} |
|
function setValues(){ |
if(!obj){ |
obj = {testF: 'testi'}; |
} |
console.log("Object is: " + dojo.toJson(obj, true)); |
dijit.byId('myForm').setValues(obj); |
} |
|
// make dojo.toJson() print dates correctly (this feels a bit dirty) |
Date.prototype.json = function(){ return dojo.date.stamp.toISOString(this, {selector: 'date'});}; |
|
var d = dojo.date.stamp.fromISOString; |
|
// These are the values assigned to the widgets in the page's HTML |
var original = { |
foo: {bar: {baz: {quux: d("2007-12-30")} } }, |
available: {from: d("2005-01-02"), to: d("2006-01-02")}, |
plop: {combo: "one"}, |
cb2: ["2", "3"], |
r2: "2", |
richtext: "<h1>original</h1><p>This is the default content</p>" |
}; |
|
// we reset the form to these values |
var changed = { |
foo: {bar: {baz: {quux: d("2005-01-01")} } }, |
available: {from: d("2005-11-02"), to: d("2006-11-02")}, |
plop: {combo: "three"}, |
cb2: ["4"], |
r2: "1", |
richtext: "<h1>changed</h1><p>This is the changed content set by setValues</p>" |
}; |
|
dojo.addOnLoad(function(){ |
doh.register("dijit.form.Form", |
[ |
function getValues(){ |
doh.is( dojo.toJson(original), dojo.toJson(dijit.byId("myForm").getValues()) ); |
}, |
function setValues(){ |
dijit.byId("myForm").setValues(changed); |
doh.is( dojo.toJson(changed), dojo.toJson(dijit.byId("myForm").getValues()) ); |
}, |
function nameAttributeSurvived(){ // ticket:4753 |
var radios = dojo.query(".RadioButton", dijit.byId("radio-cells")).forEach( |
function(r) { |
doh.is( r.inputNode.name, "r2" ); |
}); |
|
} |
] |
); |
doh.run(); |
}); |
|
</script> |
</head> |
<body> |
<h1>Form Widget Unit Test</h1> |
<p> |
The form widget takes data in a form and serializes/deserializes it, |
so it can be submitted as a JSON string of nested objects. |
</p> |
<div style="color:red">Currently only widgets are supported, not raw elements.</div> |
<form dojoType="dijit.form.Form" id="myForm" action="showPost.php" execute="alert('Execute form w/values:\n'+dojo.toJson(arguments[0],true));"> |
<p>Just HTML text</p> |
<table border=2> |
<tr><th>Description</th><th>Name</th><th>Form node/widget</th></tr> |
|
<!-- |
<tr><td>text</td><td>testF</td><td><input type="text" name="testF" value="bar1" /></td></tr> |
<tr><td>password</td><td>passwordF</td><td><input type="password" name="passwordF" value="bar4" /></td></tr> |
<tr><td>hidden</td><td>hiddenF</td><td><input type="hidden" name="hiddenF" value="bar4" /></td></tr> |
<tr><td>select</td><td>plop.noncombo</td><td> |
<div class="group"> |
<select name="plop.noncombo"> |
<option value="1">one</option> |
<option value="2">two</option> |
<option value="3">three</option> |
</select> |
</div> |
|
</td></tr> |
--> |
|
<tr><td>DateTextBox inside contentpane</td><td>foo.bar.baz.quux</td><td> |
<div dojoType="dijit.layout.ContentPane"> |
<input type="text" name="foo.bar.baz.quux" dojoType="dijit.form.DateTextBox" value="2007-12-30" /> |
</div> |
</td></tr> |
<tr><td>Layoutcontainer</td><td> |
<div dojoType="dijit.layout.LayoutContainer"> |
</div> |
</td></tr> |
<tr> |
<td>DateTextBox 1</td><td>available.from</td><td> |
<input type="text" name="available.from" dojoType="dijit.form.DateTextBox" value="2005-01-02" /> |
</td> |
</tr> |
<tr> |
<td>DateTextBox 2</td><td>available.to</td><td> |
<input type="text" name="available.to" dojoType="dijit.form.DateTextBox" value="2006-01-02" /> |
</td> |
</tr> |
|
<tr><td>ComboBox</td><td>plop.combo</td> |
<td> |
<select name="plop.combo" dojoType="dijit.form.ComboBox"> |
<option value="one">one</option> |
<option value="two">two</option> |
<option value="three">three</option> |
</select> |
</td></tr> |
|
<!-- |
<tr> |
<td>textarea</td><td>myTextArea</td> |
<td> |
<textarea name="myTextArea"> |
text text text """ \\\/ |
</textarea> |
</td> |
</tr> |
--> |
|
<!-- |
<tr> |
<td>CheckBox</td><td>cb1</td> |
<td> |
<input type="checkbox" name="cb1" value="1" /> 1 |
<input type="checkbox" name="cb1" value="2" checked="checked" /> 2 |
<input type="checkbox" name="cb1" value="3" checked="checked" /> 3 |
<input type="checkbox" name="cb1" value="4" /> 4 |
</td> |
</tr> |
--> |
|
<tr> |
<td>CheckBox widget</td><td>cb2</td> |
<td> |
<input dojoType="dijit.form.CheckBox" type="checkbox" name="cb2" value="1" /> 1 |
<input dojoType="dijit.form.CheckBox" type="checkbox" name="cb2" value="2" checked="checked" /> 2 |
<input dojoType="dijit.form.CheckBox" type="checkbox" name="cb2" value="3" checked="checked" /> 3 |
<input dojoType="dijit.form.CheckBox" type="checkbox" name="cb2" value="4" /> 4 |
</td> |
</tr> |
|
<!-- |
<tr> |
<td>radio</td><td>r1</td> |
<td> |
<input type="radio" name="r1" value="1" /> 1 |
<input type="radio" name="r1" value="2" /> 2 |
<input type="radio" name="r1" value="3" /> 3 |
<input type="radio" name="r1" value="4" /> 4 |
</td> |
</tr> |
--> |
|
<tr> |
<td>Radio widget</td><td>r2</td> |
<td id="radio-cells"> |
<input dojoType="dijit.form.RadioButton" type="radio" name="r2" value="1" /> 1 |
<input dojoType="dijit.form.RadioButton" type="radio" name="r2" value="2" checked="checked" /> 2 |
<input dojoType="dijit.form.RadioButton" type="radio" name="r2" value="3"/> 3 |
<input dojoType="dijit.form.RadioButton" type="radio" name="r2" value="4" /> 4 |
</td> |
</tr> |
<tr> |
<td>Editor widget</td><td>richtext</td> |
<td> |
<textarea dojoType="dijit.Editor" name="richtext" pluginsConfig="[{items:['bold','italic']}]"/><h1>original</h1><p>This is the default content</p></textarea> |
</td> |
</tr> |
|
</table> |
|
<button dojoType=dijit.form.Button onClick="getValues();">Get Values from form!</button> |
<button dojoType=dijit.form.Button onClick="setValues();">Set Values to form!</button> |
<button dojoType=dijit.form.Button type=submit>Submit</button> |
</form> |
|
|
</body> |
</html> |