Debian Codegraph @

dojox/mvc/tests/doh/doh_mvc_validation-test-simple.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta http-equiv="Content-type" content="text/html; charset=utf-8">
5 <title>DOH Validation Relevant Test</title>
6 <link rel="stylesheet" href="../../../../dojo/resources/dojo.css">
7 <link rel="stylesheet" href="../../../../dijit/themes/dijit.css">
8 <link rel="stylesheet" href="../../../../dijit/themes/claro/claro.css">
9 <script type="text/javascript" data-dojo-config="parseOnLoad:0,isDebug:1,async:1, mvc: {debugBindings: 1}" src="../../../../dojo/dojo.js"></script>
10 <script type="text/javascript">
11 require([
12 "doh/runner",
13 "dojo/dom-class",
14 "dojo/parser",
15 "dojo/when",
16 "dojo/Stateful",
17 "dijit/registry",
18 "dojox/mvc/ModelRefController",
19 "dijit/form/NumberTextBox",
20 "dojox/mvc/_TextBoxExtensions"
21 ], function(doh, domClass, parser, when, Stateful, registry, ModelRefController){
22
23 ctrl = new ModelRefController({
24 ownProps: {relation: 1, _setNum1Attr: 1, _setNum2Attr: 1},
25 relation: null,
26 model: new Stateful({num1: 10, num2: 20}),
27 _setNum1Attr: function(value){
28 this.set("relation", [value, this.get("num2")]);
29 this._set("num1", value);
30 },
31 _setNum2Attr: function(value){
32 this.set("relation", [this.get("num1"), value]);
33 this._set("num2", value);
34 }
35 });
36
37 disabledConverter = {
38 format: function(value){
39 return value && value[0] === value[1];
40 },
41 parse: function(value){
42 throw new Error();
43 }
44 };
45
46 validConverter = {
47 format: function(value){
48 return !value || value[0] < value[1];
49 },
50 parse: function(value){
51 throw new Error();
52 }
53 };
54
55 when(parser.parse(), function(){
56 // should be able to verify all of the inputs
57 doh.register("Check values and bindings", [
58 {
59 name: "initial",
60 runTest: function(){
61 var num1 = registry.byId("num1");
62 var num2 = registry.byId("num2");
63 doh.is(10, num1.get("value"), "num1 should be 10");
64 doh.is(20, num2.get("value"), "num2 should be 20");
65 doh.t(num1.isValid(), "num1.isValid() should be true");
66 doh.t(num2.isValid(), "num2.isValid() should be true");
67 doh.f(num2.disabled, "num2.disabled should be false");
68 doh.f(num1.disabled, "num1.disabled should be false");
69 }
70 }, {
71 name: "Update-Num1-invalid",
72 runTest: function(){
73 var num1 = registry.byId("num1");
74 var num2 = registry.byId("num2");
75 num1.set("displayedValue", "30");
76 doh.is(30, num1.get("value"), "num1 should be 30");
77 doh.f(num1.disabled, "num1.disabled should be false");
78 doh.is(20, num2.get("value"), "num2 should be 20");
79 doh.f(num2.isValid(), "num2.isValid() should be false");
80 doh.f(num2.disabled, "num2.disabled should be false");
81 doh.t(domClass.contains(num1.domNode, "dijitNumberTextBoxError"), "num1 should have the dijitNumberTextBoxError class");
82 doh.t(domClass.contains(num2.domNode, "dijitNumberTextBoxError"), "num2 should have the dijitNumberTextBoxError class");
83 }
84 }, {
85 name: "Update-Num1-disabled2",
86 runTest: function(){
87 var num1 = registry.byId("num1");
88 var num2 = registry.byId("num2");
89 num1.set("displayedValue", "21");
90 num2.set("displayedValue", "21");
91 doh.is(21, num1.get("value"), "num1 should be 21");
92 doh.is(21, num2.get("value"), "num2 should be 21");
93 doh.t(registry.byId("num2").disabled, "num2.disabled should be true");
94 doh.t(registry.byId("num1").disabled, "num1.disabled should be true");
95 }
96 }
97 ]);
98
99 doh.run();
100 });
101 });
102 </script>
103 </head>
104 <body class="claro">
105 <script type="dojo/require">at: "dojox/mvc/at"</script>
106 <form method="post">
107 <div>
108 <label for="num1">Number 1</label>
109 <input id="num1" data-dojo-type="dijit.form.NumberTextBox"
110 data-dojo-props="value: at(ctrl, 'num1'),
111 disabled: at(ctrl, 'relation').transform(disabledConverter),
112 valid: at(ctrl, 'relation').transform(validConverter)">
113 </div>
114 <div>
115 <label for="num2">Number 2</label>
116 <input id="num2" data-dojo-type="dijit.form.NumberTextBox"
117 data-dojo-props="value: at(ctrl, 'num2'),
118 disabled: at(ctrl, 'relation').transform(disabledConverter),
119 valid: at(ctrl, 'relation').transform(validConverter)">
120 </div>
121 </form>
122 </body>
123 </html>