| 1 | <!DOCTYPE HTML> |
| 2 | <html> |
| 3 | <head> |
| 4 | <meta http-equiv="content-type" content="text/html; charset=utf-8"/> |
| 5 | <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no" /> |
| 6 | <meta name="apple-mobile-web-app-capable" content="yes" /> |
| 7 | <title>Radio Button Tests</title> |
| 8 | <script type="text/javascript" src="../../../deviceTheme.js"></script> |
| 9 | <script type="text/javascript" src="../../../../../dojo/dojo.js" data-dojo-config="async: true, parseOnLoad: true"></script> |
| 10 | <script language="JavaScript" type="text/javascript"> |
| 11 | require([ |
| 12 | "dojo/dom-construct", // dojo.place |
| 13 | "dojo/dom-class", // dojo.hasClass |
| 14 | "dojo/ready", // dojo.ready |
| 15 | "dijit/registry", // dijit.byId |
| 16 | "doh/runner", //doh functions |
| 17 | "dojox/mobile/RadioButton", |
| 18 | "dojox/mobile", // This is a mobile app. |
| 19 | "dojox/mobile/View", // This mobile app uses mobile view |
| 20 | "dojox/mobile/compat", // This mobile app supports running on desktop browsers |
| 21 | "dojox/mobile/parser" // This mobile app uses declarative programming with fast mobile parser |
| 22 | ], function(domConst, domClass, ready, registry, runner, RadioButton){ |
| 23 | |
| 24 | function _createRadioButtonDeclaratively(buttonId) { |
| 25 | return registry.byId(buttonId); |
| 26 | }; |
| 27 | |
| 28 | function _createRadioButtonProgrammatically(buttonValue, buttonName, placeHolderId){ |
| 29 | var button = new RadioButton({value:buttonValue, name:buttonName}); |
| 30 | runner.assertNotEqual(null, button); |
| 31 | domConst.place(button.domNode, placeHolderId, "replace"); |
| 32 | button.startup(); |
| 33 | return button; |
| 34 | }; |
| 35 | |
| 36 | function _createRadioButtonProgrammaticallyWithSourceNodeReference(buttonValue, buttonName, buttonId){ |
| 37 | return new RadioButton({value:buttonValue, name:buttonName}, buttonId); |
| 38 | }; |
| 39 | |
| 40 | function _assertCorrectRadioButton(button1, button2, button3){ |
| 41 | runner.assertNotEqual(null, button1, button1.toString()); |
| 42 | runner.assertNotEqual(null, button2, button2.toString()); |
| 43 | runner.assertNotEqual(null, button3, button3.toString()); |
| 44 | |
| 45 | runner.assertFalse(button1.checked, button1.toString()); |
| 46 | runner.assertFalse(button2.checked, button2.toString()); |
| 47 | runner.assertFalse(button3.checked, button3.toString()); |
| 48 | |
| 49 | button1.set("checked", true); |
| 50 | runner.assertTrue(button1.checked, button1.toString()); |
| 51 | runner.assertFalse(button2.checked, button2.toString()); |
| 52 | runner.assertFalse(button3.checked, button3.toString()); |
| 53 | |
| 54 | button2.set("checked", true); |
| 55 | runner.assertFalse(button1.checked, button1.toString()); |
| 56 | runner.assertTrue(button2.checked, button2.toString()); |
| 57 | runner.assertFalse(button3.checked, button3.toString()); |
| 58 | }; |
| 59 | |
| 60 | function _showView2(){ |
| 61 | var view1 = registry.byId("view1"); |
| 62 | view1.performTransition("view2", 1, "none"); |
| 63 | }; |
| 64 | |
| 65 | ready(function(){ |
| 66 | runner.register("dojox.mobile.test.doh.ButtonTests", [ |
| 67 | function testInView1(){ |
| 68 | var button11 = _createRadioButtonDeclaratively("view1-button11"); |
| 69 | var button12 = _createRadioButtonDeclaratively("view1-button12"); |
| 70 | var button13 = _createRadioButtonDeclaratively("view1-button13"); |
| 71 | |
| 72 | var button21 = _createRadioButtonProgrammatically("1", "view1-button2", "view1-button21"); |
| 73 | var button22 = _createRadioButtonProgrammatically("2", "view1-button2", "view1-button22"); |
| 74 | var button23 = _createRadioButtonProgrammatically("3", "view1-button2", "view1-button23"); |
| 75 | |
| 76 | var button31 = _createRadioButtonProgrammaticallyWithSourceNodeReference("1", "view1-button3", "view1-button31"); |
| 77 | var button32 = _createRadioButtonProgrammaticallyWithSourceNodeReference("2", "view1-button3", "view1-button32"); |
| 78 | var button33 = _createRadioButtonProgrammaticallyWithSourceNodeReference("3", "view1-button3", "view1-button33"); |
| 79 | |
| 80 | _assertCorrectRadioButton(button11, button12, button13); |
| 81 | _assertCorrectRadioButton(button21, button22, button23); |
| 82 | _assertCorrectRadioButton(button31, button32, button33); |
| 83 | }, |
| 84 | function testInView2(){ |
| 85 | var button11 = _createRadioButtonDeclaratively("view2-button11"); |
| 86 | var button12 = _createRadioButtonDeclaratively("view2-button12"); |
| 87 | var button13 = _createRadioButtonDeclaratively("view2-button13"); |
| 88 | |
| 89 | var button21 = _createRadioButtonProgrammatically("1", "view2-button2", "view2-button21"); |
| 90 | var button22 = _createRadioButtonProgrammatically("2", "view2-button2", "view2-button22"); |
| 91 | var button23 = _createRadioButtonProgrammatically("3", "view2-button2", "view2-button23"); |
| 92 | |
| 93 | var button31 = _createRadioButtonProgrammaticallyWithSourceNodeReference("1", "view2-button3", "view2-button31"); |
| 94 | var button32 = _createRadioButtonProgrammaticallyWithSourceNodeReference("2", "view2-button3", "view2-button32"); |
| 95 | var button33 = _createRadioButtonProgrammaticallyWithSourceNodeReference("3", "view2-button3", "view2-button33"); |
| 96 | |
| 97 | _showView2(); |
| 98 | |
| 99 | _assertCorrectRadioButton(button11, button12, button13); |
| 100 | _assertCorrectRadioButton(button21, button22, button23); |
| 101 | _assertCorrectRadioButton(button31, button32, button33); |
| 102 | } |
| 103 | ]); |
| 104 | runner.run(); |
| 105 | }); |
| 106 | }) |
| 107 | </script> |
| 108 | </head> |
| 109 | <body> |
| 110 | <div id="view1" data-dojo-type="dojox.mobile.View" selected="true"> |
| 111 | <h1>View 1</h1> |
| 112 | <input id="view1-button11" type="radio" name="view1-button1" value="1" data-dojo-type="dojox.mobile.RadioButton"> |
| 113 | <input id="view1-button12" type="radio" name="view1-button1" value="2" data-dojo-type="dojox.mobile.RadioButton"> |
| 114 | <input id="view1-button13" type="radio" name="view1-button1" value="3" data-dojo-type="dojox.mobile.RadioButton"> |
| 115 | <br> |
| 116 | <div id="view1-button21"></div> |
| 117 | <div id="view1-button22"></div> |
| 118 | <div id="view1-button23"></div> |
| 119 | <br> |
| 120 | <input id="view1-button31" type="radio"> |
| 121 | <input id="view1-button32" type="radio"> |
| 122 | <input id="view1-button33" type="radio"> |
| 123 | </div> |
| 124 | <div id="view2" data-dojo-type="dojox.mobile.View"> |
| 125 | <h1>View 2</h1> |
| 126 | <input id="view2-button11" type="radio" name="view2-button1" value="1" data-dojo-type="dojox.mobile.RadioButton"> |
| 127 | <input id="view2-button12" type="radio" name="view2-button1" value="2" data-dojo-type="dojox.mobile.RadioButton"> |
| 128 | <input id="view2-button13" type="radio" name="view2-button1" value="3" data-dojo-type="dojox.mobile.RadioButton"> |
| 129 | <br> |
| 130 | <div id="view2-button21"></div> |
| 131 | <div id="view2-button22"></div> |
| 132 | <div id="view2-button23"></div> |
| 133 | <br> |
| 134 | <input id="view2-button31" type="radio"> |
| 135 | <input id="view2-button32" type="radio"> |
| 136 | <input id="view2-button33" type="radio"> |
| 137 | </div> |
| 138 | </body> |
| 139 | </html> |