Debian Codegraph @

dojox/mvc/tests/1.7/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" djConfig="parseOnLoad:0,isDebug:1,async:1" src="../../../../../dojo/dojo.js"></script>
10 <script type="text/javascript">
11 var model;
12 require([
13 'dojo/_base/declare',
14 'dojo/parser',
15 'dojox/mvc',
16 'dojox/mvc/StatefulModel',
17 'dojo/_base/lang',
18 "dojo/_base/html",
19 'dijit/form/Button'
20 ], function (declare, parser, mvc, StatefulModel, lang, html) {
21 var Model = declare([StatefulModel], {
22 constructor: function (args) {
23 mvc.bindInputs([this.num1, this.num2], lang.hitch(this, '_checkNums'));
24 },
25
26 _checkNums: function () {
27 var num1Val = this.num1.get('value'),
28 num2Val = this.num2.get('value');
29
30 this.num1.set({
31 relevant: num1Val !== num2Val,
32 valid: num1Val <= num2Val
33 });
34
35 this.num2.set({
36 relevant: num1Val !== num2Val,
37 valid: num1Val <= num2Val
38 });
39 }
40 });
41
42 model = new Model({
43 data: {
44 num1: 10,
45 num2: 20
46 }
47 });
48 require([
49 'doh/runner', 'dijit/dijit'
50 ], function(){
51 require([
52 'dojo/domReady!'
53 ], function(){
54 doh.register("parse", function() {
55 dojo.parser.parse();
56 });
57 // should be able to verify all of the inputs
58 doh.register("check initial values and bindings", [{
59 name : "initial",
60 runTest : function() {
61 num1 = dijit.byId("num1");
62 num2 = dijit.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
72 doh.register("update num1 invalid", [{
73 name : "Update-Num1-invalid",
74 runTest : function() {
75 num1 = dijit.byId("num1");
76 num2 = dijit.byId("num2");
77 num1.set("value","30");
78 doh.is("30", num1.get('value'),"num1 should be 30");
79 doh.f(num1.disabled,"num1.disabled should be false");
80 doh.is("20", num2.get('value'),"num2 should be 20");
81 doh.f(num2.isValid(),"num2.isValid() should be false");
82 doh.f(num2.disabled,"num2.disabled should be false");
83 doh.t(dojo.hasClass('widget_num1','dijitNumberTextBoxError'),"num1 should have the dijitNumberTextBoxError class");
84 doh.t(dojo.hasClass('widget_num2','dijitNumberTextBoxError'),"num2 should have the dijitNumberTextBoxError class");
85 }
86 }]);
87
88 doh.register("update num1 disabled2", [{
89 name : "Update-Num1-disabled2",
90 runTest : function() {
91 num1 = dijit.byId("num1");
92 num2 = dijit.byId("num2");
93 num1.set("value","21");
94 num2.set("value","21");
95 doh.is("21", num1.get('value'),"num1 should be 30");
96 doh.is("21", num2.get('value'),"num2 should be 20");
97 doh.t(dijit.byId("num2").disabled,"num2.disabled should be true");
98 doh.t(dijit.byId("num1").disabled,"num1.disabled should be true");
99
100 model.reset();
101 }
102 }]);
103
104 doh.run();
105
106 });
107 });
108 });
109
110 </script>
111 </head>
112 <body class="claro">
113 <form method="post">
114 <div>
115 <label for="num1">Number 1</label>
116 <input data-dojo-props="ref:model.num1" data-dojo-type="dijit.form.NumberTextBox" id="num1">
117 </div>
118 <div>
119 <label for="num2">Number 2</label>
120 <input data-dojo-props="ref:model.num2" data-dojo-type="dijit.form.NumberTextBox" id="num2">
121 </div>
122 </form>
123 <br/>Model:
124 <button id="reset" type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){doReset()}">Reset</button>
125
126 <script type="text/javascript">
127 function doReset() {
128 model.reset();
129 }
130 </script>
131
132 </body>
133
134 </html>