| 1 |
<!DOCTYPE html> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> |
| 5 |
<title>Testing MultiSelect form widget | The Dojo Toolkit</title> |
| 6 |
|
| 7 |
<style type="text/css"> |
| 8 |
@import "../../../../dijit/tests/css/dijitTests.css"; |
| 9 |
#select1, #select2, #select3 { |
| 10 |
width:255px; |
| 11 |
height:300px; |
| 12 |
overflow:auto; |
| 13 |
} |
| 14 |
div#sel1, div#sel2,div#sel3 { |
| 15 |
float: left; |
| 16 |
|
| 17 |
} |
| 18 |
div#leftRightButtons,div#leftRightButtons2 { |
| 19 |
float: left; |
| 20 |
padding: 10em 0.5em 0 0.5em; |
| 21 |
} |
| 22 |
</style> |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
<link id="themeStyles" rel="stylesheet" href="../../../../dijit/themes/claro/claro.css"/> |
| 27 |
|
| 28 |
|
| 29 |
<script type="text/javascript" src="../../../../dojo/dojo.js" |
| 30 |
data-dojo-config="isDebug: true, parseOnLoad: true, has: { 'dojo-bidi': true }"></script> |
| 31 |
|
| 32 |
|
| 33 |
<script type="text/javascript" src="../../_testCommon.js"></script> |
| 34 |
|
| 35 |
<script type="text/javascript"> |
| 36 |
var globalId = null; |
| 37 |
|
| 38 |
dojo.require("dijit.form.MultiSelect"); |
| 39 |
|
| 40 |
// needed for tests: |
| 41 |
dojo.require("dijit.form.Form"); |
| 42 |
dojo.require("dijit.form.Button"); |
| 43 |
dojo.require("dijit.layout.SplitContainer"); |
| 44 |
|
| 45 |
dojo.require("dojo.parser"); // scan page for widgets and instantiate them |
| 46 |
dojo.require("doh.runner"); |
| 47 |
|
| 48 |
dojo.ready(function(){ |
| 49 |
|
| 50 |
// ref a clonable node, then split it between two selects |
| 51 |
var c = dojo.query(".clone")[0]; |
| 52 |
var l = -1; |
| 53 |
opt = function(){ |
| 54 |
return dojo.byId((++l%2 == 0 ? "select1":"select2" )); |
| 55 |
}; |
| 56 |
|
| 57 |
// turn any non-data-dojo-type selects into widgets programatically: |
| 58 |
dojo.query("select").forEach(function(n){ |
| 59 |
if(!dijit.byNode(n)){ |
| 60 |
var textDir = n.id == "select3" ? "" : (n.id == "select1" ? "rtl" : "auto"); |
| 61 |
var foo = new dijit.form.MultiSelect({ textDir: textDir ,name: n.name }, n); |
| 62 |
} |
| 63 |
}); |
| 64 |
|
| 65 |
// programatic |
| 66 |
var myWidget = new dijit.form.MultiSelect({textDir: "auto"}); |
| 67 |
myWidget.placeAt(dojo.body()); |
| 68 |
globalId = myWidget.id; |
| 69 |
|
| 70 |
// listen to the "move items" buttons |
| 71 |
dojo.query("button.switch") |
| 72 |
.connect("onclick",function(e){ |
| 73 |
switch(e.target.id.toString()){ |
| 74 |
case "button21" : dijit.byId("select1").addSelected(dijit.byId("select2")); break; |
| 75 |
case "button12" : dijit.byId("select2").addSelected(dijit.byId("select1")); break; |
| 76 |
case "button32" : dijit.byId("select2").addSelected(dijit.byId("select3")); break; |
| 77 |
case "button23" : dijit.byId("select3").addSelected(dijit.byId("select2")); break; |
| 78 |
case "up" : dijit.byId("select4").addSelected(dijit.byId(globalId)); break; |
| 79 |
case "down" : dijit.byId(globalId).addSelected(dijit.byId("select4")); break; |
| 80 |
} |
| 81 |
}); |
| 82 |
|
| 83 |
// listen to the invert buttons |
| 84 |
dojo.query("button.invert") |
| 85 |
.connect("onclick",function(e){ |
| 86 |
switch(e.target.id.toString()){ |
| 87 |
case "i1" : dijit.byId("select1").invertSelection(); break; |
| 88 |
case "i2" : dijit.byId("select2").invertSelection(); break; |
| 89 |
case "i3" : dijit.byId("select4").invertSelection(); break; |
| 90 |
case "i4" : dijit.byId("select3").invertSelection(); break; |
| 91 |
} |
| 92 |
}); |
| 93 |
|
| 94 |
// there is only one debug button |
| 95 |
dojo.query(".debug").connect("onclick",function(e){ |
| 96 |
console.log('select1 value:',dijit.byId("select1").get('value') + '/' + dijit.byId("select1").value); |
| 97 |
console.log('select2 value:',dijit.byId("select2").get('value') + '/' + dijit.byId("select2").value); |
| 98 |
console.log('select3 value:',dijit.byId("select3").get('value') + '/' + dijit.byId("select3").value); |
| 99 |
console.log('select4 value:',dijit.byId("select4").get('value') + '/' + dijit.byId("select4").value); |
| 100 |
}); |
| 101 |
|
| 102 |
dojo.connect(dojo.byId("formSubmit"), "onclick", function(e){ |
| 103 |
// see what the real form says about our widgets: |
| 104 |
var vals = dojo.formToJson("test"); |
| 105 |
console.log(vals); |
| 106 |
}); |
| 107 |
|
| 108 |
// Testing: |
| 109 |
var originalList = [ |
| 110 |
"Tennessee...", |
| 111 |
"\u05d5\u05d9\u05e8\u05d2\u0027\u05d9\u05e0\u05d9\u05d4...", |
| 112 |
"Washington...", |
| 113 |
"Florida...", |
| 114 |
"California..." |
| 115 |
]; |
| 116 |
var valueList = [ |
| 117 |
"Tennessee...", |
| 118 |
"\u05d5\u05d9\u05e8\u05d2\u0027\u05d9\u05e0\u05d9\u05d4...", |
| 119 |
"WA", |
| 120 |
"FL", |
| 121 |
"CA" |
| 122 |
]; |
| 123 |
var lreList = [ |
| 124 |
"\u202ATennessee...\u202C", |
| 125 |
"\u202A\u05d5\u05d9\u05e8\u05d2\u0027\u05d9\u05e0\u05d9\u05d4...\u202C", |
| 126 |
"\u202AWashington...\u202C", |
| 127 |
"\u202AFlorida...\u202C", |
| 128 |
"\u202ACalifornia...\u202C" |
| 129 |
]; |
| 130 |
var rleList = [ |
| 131 |
"\u202BTennessee...\u202C", |
| 132 |
"\u202B\u05d5\u05d9\u05e8\u05d2\u0027\u05d9\u05e0\u05d9\u05d4...\u202C", |
| 133 |
"\u202BWashington...\u202C", |
| 134 |
"\u202BFlorida...\u202C", |
| 135 |
"\u202BCalifornia...\u202C" |
| 136 |
]; |
| 137 |
var autoList = [ |
| 138 |
"\u202ATennessee...\u202C", |
| 139 |
"\u202B\u05d5\u05d9\u05e8\u05d2\u0027\u05d9\u05e0\u05d9\u05d4...\u202C", |
| 140 |
"\u202AWashington...\u202C", |
| 141 |
"\u202AFlorida...\u202C", |
| 142 |
"\u202ACalifornia...\u202C" |
| 143 |
]; |
| 144 |
doh.register("parse", { |
| 145 |
name: "parse", |
| 146 |
timeout: 5000, |
| 147 |
runTest: function() { |
| 148 |
dojo.parser.parse(); |
| 149 |
} |
| 150 |
}); |
| 151 |
var select1 = dijit.byId("select1"), |
| 152 |
select2 = dijit.byId("select2"), |
| 153 |
select3 = dijit.byId("select3"), |
| 154 |
select4 = dijit.byId("select4"), |
| 155 |
select5 = dijit.byId(globalId), |
| 156 |
|
| 157 |
button12 = dojo.byId("button12"), |
| 158 |
button21 = dojo.byId("button21"), |
| 159 |
button32 = dojo.byId("button32"), |
| 160 |
button23 = dojo.byId("button23"), |
| 161 |
buttonUp = dojo.byId("up"), |
| 162 |
buttonDown = dojo.byId("down"), |
| 163 |
|
| 164 |
bidiLtr, bidiRtl, bidiAuto; |
| 165 |
|
| 166 |
doh.register("test multiSelect", [ |
| 167 |
{ |
| 168 |
name:"initial direction of the Lists", |
| 169 |
|
| 170 |
runTest:function(){ |
| 171 |
doh.is("rtl", select1.textDir, "textDir of - " + select1.id); |
| 172 |
doh.is("auto", select2.textDir, "textDir of - " + select2.id); |
| 173 |
doh.is("rtl", select4.textDir, "textDir of - " + select4.id); |
| 174 |
doh.is("auto", select5.textDir, "textDir of - " + select5.id); |
| 175 |
} |
| 176 |
}, |
| 177 |
{ |
| 178 |
name:"test options: select1, select4", |
| 179 |
|
| 180 |
runTest:function(){ |
| 181 |
var select1 = dijit.byId("select1"), select4 = dijit.byId("select4"); |
| 182 |
var select1OptionsArr = select1.containerNode.options; |
| 183 |
var select4OptionsArr = select4.containerNode.options; |
| 184 |
for(var index = 0; index < select1.containerNode.options.length; index++){ |
| 185 |
|
| 186 |
doh.is(rleList[index], select1OptionsArr[index].text, "select1 - option.text: " + (index + 1)); |
| 187 |
doh.is(valueList[index], select1OptionsArr[index].value, "select1 - option.value: " + (index + 1)); |
| 188 |
|
| 189 |
doh.is(rleList[index], select4OptionsArr[index].text, "select4 - option.text: " + (index + 1)); |
| 190 |
doh.is(valueList[index], select4OptionsArr[index].value, "select4 - option.value: " + (index + 1)); |
| 191 |
|
| 192 |
} |
| 193 |
} |
| 194 |
}, |
| 195 |
{ |
| 196 |
name:"set value: select1, select2", |
| 197 |
|
| 198 |
runTest:function(){ |
| 199 |
|
| 200 |
var select1OptionsArr = select1.containerNode.options; |
| 201 |
var select2OptionsArr = select2.containerNode.options; |
| 202 |
|
| 203 |
select1.set("value", ["Tennessee...","\u05d5\u05d9\u05e8\u05d2\u0027\u05d9\u05e0\u05d9\u05d4...","FL","CA"]); |
| 204 |
button12.click(); |
| 205 |
|
| 206 |
// Florida button21 |
| 207 |
doh.is(rleList[2], select1OptionsArr[0].text, "select1 - option.text: " + 1); |
| 208 |
doh.is(valueList[2], select1OptionsArr[0].value, "select1 - option.value: " + 1); |
| 209 |
|
| 210 |
doh.is(autoList[0], select2OptionsArr[0].text, "select2 - option.text: " + 1); |
| 211 |
doh.is(valueList[0], select2OptionsArr[0].value, "select2 - option.value: " + 1); |
| 212 |
|
| 213 |
doh.is(autoList[1], select2OptionsArr[1].text, "select2 - option.text: " + 2); |
| 214 |
doh.is(valueList[1], select2OptionsArr[1].value, "select2 - option.value: " + 2); |
| 215 |
|
| 216 |
doh.is(autoList[3], select2OptionsArr[2].text, "select2 - option.text: " + 3); |
| 217 |
doh.is(valueList[3], select2OptionsArr[2].value, "select2 - option.value: " + 3); |
| 218 |
|
| 219 |
doh.is(autoList[4], select2OptionsArr[3].text, "select2 - option.text: " + 4); |
| 220 |
doh.is(valueList[4], select2OptionsArr[3].value, "select2 - option.value: " + 4); |
| 221 |
|
| 222 |
} |
| 223 |
}, |
| 224 |
{ |
| 225 |
name:"set value: select2, select3", |
| 226 |
|
| 227 |
runTest:function(){ |
| 228 |
|
| 229 |
var d = new doh.Deferred(); |
| 230 |
|
| 231 |
//select1.set("value", ["Tennessee...","\u05d5\u05d9\u05e8\u05d2\u0027\u05d9\u05e0\u05d9\u05d4...","FL","CA"]); |
| 232 |
button23.click(); |
| 233 |
|
| 234 |
var select3OptionsArr = select3.containerNode.options; |
| 235 |
|
| 236 |
doh.is(originalList[0], select3OptionsArr[0].text, "select3 - option.text: " + 1); |
| 237 |
doh.is(valueList[0], select3OptionsArr[0].value, "select3 - option.value: " + 1); |
| 238 |
|
| 239 |
doh.is(originalList[1], select3OptionsArr[1].text, "select3 - option.text: " + 2); |
| 240 |
doh.is(valueList[1], select3OptionsArr[1].value, "select3 - option.value: " + 2); |
| 241 |
|
| 242 |
doh.is(originalList[3], select3OptionsArr[2].text, "select3 - option.text: " + 3); |
| 243 |
doh.is(valueList[3], select3OptionsArr[2].value, "select3 - option.value: " + 3); |
| 244 |
|
| 245 |
doh.is(originalList[4], select3OptionsArr[3].text, "select3 - option.text: " + 4); |
| 246 |
doh.is(valueList[4], select3OptionsArr[3].value, "select3 - option.value: " + 4); |
| 247 |
|
| 248 |
select3.set("value", ["\u05d5\u05d9\u05e8\u05d2\u0027\u05d9\u05e0\u05d9\u05d4...","FL","CA"]); |
| 249 |
button32.click(); |
| 250 |
|
| 251 |
var select2OptionsArr = select2.containerNode.options; |
| 252 |
|
| 253 |
setTimeout(d.getTestCallback(function(){ |
| 254 |
doh.is(autoList[1], select2OptionsArr[0].text, "select2 - option.text: " + 1); |
| 255 |
doh.is(valueList[1], select2OptionsArr[0].value, "select2 - option.value: " + 1); |
| 256 |
|
| 257 |
doh.is(autoList[3], select2OptionsArr[1].text, "select2 - option.text: " + 2); |
| 258 |
doh.is(valueList[3], select2OptionsArr[1].value, "select2 - option.value: " + 2); |
| 259 |
|
| 260 |
doh.is(autoList[4], select2OptionsArr[2].text, "select2 - option.text: " + 3); |
| 261 |
doh.is(valueList[4], select2OptionsArr[2].value, "select2 - option.value: " + 3); |
| 262 |
}), 100); |
| 263 |
return d; |
| 264 |
|
| 265 |
} |
| 266 |
}, |
| 267 |
{ |
| 268 |
name:"set value: select4, select5", |
| 269 |
|
| 270 |
runTest:function(){ |
| 271 |
|
| 272 |
var d = new doh.Deferred(); |
| 273 |
|
| 274 |
select4.set("value", ["Tennessee...","\u05d5\u05d9\u05e8\u05d2\u0027\u05d9\u05e0\u05d9\u05d4...","FL","CA"]); |
| 275 |
buttonDown.click(); |
| 276 |
|
| 277 |
var select5OptionsArr = select5.containerNode.options; |
| 278 |
|
| 279 |
doh.is(autoList[0], select5OptionsArr[0].text, "select5 - option.text: " + 1); |
| 280 |
doh.is(valueList[0], select5OptionsArr[0].value, "select5 - option.value: " + 1); |
| 281 |
|
| 282 |
doh.is(autoList[1], select5OptionsArr[1].text, "select5 - option.text: " + 2); |
| 283 |
doh.is(valueList[1], select5OptionsArr[1].value, "select5 - option.value: " + 2); |
| 284 |
|
| 285 |
doh.is(autoList[3], select5OptionsArr[2].text, "select5 - option.text: " + 3); |
| 286 |
doh.is(valueList[3], select5OptionsArr[2].value, "select5 - option.value: " + 3); |
| 287 |
|
| 288 |
doh.is(autoList[4], select5OptionsArr[3].text, "select5 - option.text: " + 4); |
| 289 |
doh.is(valueList[4], select5OptionsArr[3].value, "select5 - option.value: " + 4); |
| 290 |
|
| 291 |
select5.set("value", ["\u05d5\u05d9\u05e8\u05d2\u0027\u05d9\u05e0\u05d9\u05d4...","FL","CA"]); |
| 292 |
buttonUp.click(); |
| 293 |
|
| 294 |
var select4OptionsArr = select4.containerNode.options; |
| 295 |
|
| 296 |
setTimeout(d.getTestCallback(function(){ |
| 297 |
doh.is(rleList[2], select4OptionsArr[0].text, "select4 - option.text: " + 1); |
| 298 |
doh.is(valueList[2], select4OptionsArr[0].value, "select4 - option.value: " + 1); |
| 299 |
|
| 300 |
doh.is(rleList[1], select4OptionsArr[1].text, "select4 - option.text: " + 2); |
| 301 |
doh.is(valueList[1], select4OptionsArr[1].value, "select4 - option.value: " + 2); |
| 302 |
|
| 303 |
doh.is(rleList[3], select4OptionsArr[2].text, "select4 - option.text: " + 3); |
| 304 |
doh.is(valueList[3], select4OptionsArr[2].value, "select4 - option.value: " + 3); |
| 305 |
|
| 306 |
doh.is(rleList[4], select4OptionsArr[3].text, "select4 - option.text: " + 3); |
| 307 |
doh.is(valueList[4], select4OptionsArr[3].value, "select4 - option.value: " + 3); |
| 308 |
}), 100); |
| 309 |
return d; |
| 310 |
|
| 311 |
} |
| 312 |
} |
| 313 |
]); |
| 314 |
doh.run(); |
| 315 |
}); |
| 316 |
</script> |
| 317 |
</head> |
| 318 |
<body class="claro" style="padding:20px"> |
| 319 |
|
| 320 |
<h1 class="testTitle">dijit.form.MultiSelect:</h1> |
| 321 |
<p>Select one or more items in First or Second list and move them between lists using the buttons provided.</p> |
| 322 |
<form action="#" method="get" id="test" onsubmit="return false"> |
| 323 |
|
| 324 |
<div> |
| 325 |
<div id="sel1" role="presentation"> |
| 326 |
<label for="select1">First list:</label><br> |
| 327 |
<select id="select1" multiple size="7" tabindex="1" name="first"> |
| 328 |
<option selected>Tennessee...</option> |
| 329 |
<option >וירג'יניה...</option> |
| 330 |
<option value="WA">Washington...</option> |
| 331 |
<option value="FL">Florida...</option> |
| 332 |
<option value="CA">California...</option> |
| 333 |
</select> |
| 334 |
</div> |
| 335 |
<div id="leftRightButtons" role="presentation"> |
| 336 |
<span> |
| 337 |
<button class="switch" id="button21" title="Move Items to First list"><</button> |
| 338 |
<button class="switch" id="button12" title="Move Items to Second list">></button> |
| 339 |
</span> |
| 340 |
</div> |
| 341 |
<div id="sel2" role="presentation"> |
| 342 |
<label for="select2">Second list:</label><br> |
| 343 |
<select id="select2" multiple size="7" name="second"> |
| 344 |
</select> |
| 345 |
</div> |
| 346 |
<div id="leftRightButtons2" role="presentation"> |
| 347 |
<span> |
| 348 |
<button class="switch" id="button32" title="Move Items to Third list"><</button> |
| 349 |
<button class="switch" id="button23" title="Move Items to Second list">></button> |
| 350 |
</span> |
| 351 |
</div> |
| 352 |
<div id="sel3" role="presentation"> |
| 353 |
<label for="select3">Third list:</label><br> |
| 354 |
<select id="select3" multiple size="7" name="third"> |
| 355 |
</select> |
| 356 |
</div> |
| 357 |
</div> |
| 358 |
|
| 359 |
<br style="clear: both;"/><br> |
| 360 |
|
| 361 |
<button class='invert' id="i1">invert first list</button> |
| 362 |
<button class="invert" id="i2">invert second list</button> |
| 363 |
<button class="invert" id="i4">invert third list</button> |
| 364 |
<button id="formSubmit" type="submit">Submit</button> |
| 365 |
<button class="debug">call get('value')</button> |
| 366 |
|
| 367 |
<h3><label for="select4">markup:</label></h3> |
| 368 |
|
| 369 |
<select id="select4" multiple data-dojo-type="dijit.form.MultiSelect" |
| 370 |
data-dojo-props='textDir:"rtl",name:"select4", |
| 371 |
style:{height:"200px", width:"175px", border:"5px solid #ededed"}' name="fourth"> |
| 372 |
|
| 373 |
<option selected>Tennessee...</option> |
| 374 |
<option >וירג'יניה...</option> |
| 375 |
<option value="WA">Washington...</option> |
| 376 |
<option value="FL">Florida...</option> |
| 377 |
<option value="CA">California...</option> |
| 378 |
</select> |
| 379 |
<br><br> |
| 380 |
<button class="switch" id="up">move up</button> |
| 381 |
<button class="switch" id="down">move Down</button> |
| 382 |
<br> |
| 383 |
|
| 384 |
</body> |
| 385 |
</html> |