Debian Codegraph @

dijit/tests/form/test_validate.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta http-equiv="Content-type" content="text/html; charset=utf-8">
5 <title>Test TextBox Validation Widgets</title>
6
7 <style type="text/css">
8 @import "../../themes/claro/document.css";
9 @import "../css/dijitTests.css";
10
11 .testExample {
12 background-color:#fbfbfb;
13 padding:1em;
14 margin-bottom:1em;
15 border:1px solid #bfbfbf;
16 }
17
18 body .small {
19 width: 3em;
20 }
21 body .medium {
22 width: 10em;
23 }
24 body .long {
25 width: 20em;
26 }
27 body .verylong {
28 width: 90%;
29 }
30
31 .noticeMessage {
32 color:#093669;
33 font-size:0.95em;
34 margin-left:0.5em;
35 }
36
37 .dojoTitlePaneLabel label {
38 font-weight:bold;
39 }
40 #widget_q26 .dijitInputField {
41 padding:10px !important;
42 }
43
44 .monospace .dijitTextBox {
45 font-family: monospace;
46 }
47
48 .sans {
49 font-family: sans-serif;
50 }
51 </style>
52
53 <!-- required: the default dijit theme: -->
54 <link id="themeStyles" rel="stylesheet" href="../../themes/claro/claro.css"/>
55
56 <!--
57 required: dojo.js
58 Note that the locale is hardcoded to english, for benefit of the robot/ValidationTextBox.html test
59 (when running on a non-US computer).
60 -->
61 <script type="text/javascript" src="../../../dojo/dojo.js"
62 data-dojo-config="isDebug: true, parseOnLoad: true, locale: 'en-us', extraLocale: ['de-de']"></script>
63
64 <!-- only needed for alternate theme testing: -->
65 <script type="text/javascript" src="../_testCommon.js"></script>
66
67 <script type="text/javascript">
68 dojo.require("doh.runner");
69
70 dojo.require("dijit.form.TextBox");
71 dojo.require("dijit.form.ValidationTextBox");
72 dojo.require("dijit.form.NumberTextBox");
73 dojo.require("dijit.form.CurrencyTextBox");
74
75 dojo.require("dijit.Dialog");
76 dojo.require("dijit.form.Button");
77 dojo.require("dijit.tests.helpers"); // functions to help test
78
79 dojo.require("dojo.currency");
80 dojo.require("dojo.parser"); // scan page for widgets and instantiate them
81
82 // Add test=true to the URL to run unit tests.
83 var test = /mode=test/i.test(window.location.href);
84
85 function fixNbsp(val){
86 return typeof val == "string" ? val.replace(/\xA0/g, " ") : val;
87 }
88
89 dojo.ready(function(){
90
91 new dijit.form.TextBox({id: 'monospace1', "aria-label":"monospace1", disabled: true, value: 'M|M:monospace?'}, 'monospace1');
92 new dijit.form.TextBox({id: 'monospace2', "aria-label":"monospace2",disabled: true, value: 'M|M:monospace?'}).placeAt('widget_monospace1', 'after');
93
94 new dijit.form.TextBox({id: 'sans1', "aria-label":"sans1", disabled: true, value: 'sans1'}, 'sans1');
95 new dijit.form.TextBox({id: 'sans2', "aria-label":"sans2", disabled: true, value: 'sans2'}).placeAt('widget_sans1', 'after');
96
97 // See if we can make a widget in script and attach it to the DOM ourselves.
98 var props = {
99 name: "elevation",
100 value: 3000,
101 constraints: {min:-20000,max:20000,places:0,allowCruft:true},
102 promptMessage: "Enter a value between -20000 and +20000",
103 required: true,
104 style:{ textAlign: document.documentElement.dir == "rtl" ? "left" : "right" },
105 editOptions:{pattern:'#,##0'},
106 invalidMessage: "Invalid elevation.",
107 onChange: function(val){dojo.byId('oc5').value = val; },
108 "class": "medium"
109 };
110 (new dojo.declare("customNumberTextBox", dijit.form.NumberTextBox, props)({}, "q05")).startup();
111
112 props = {
113 name: "ticket1651",
114 id: "mname",
115 templateString: null, // #11493
116 templatePath: dojo.moduleUrl('dijit.form.templates', 'TextBox.html'),
117 value: null,
118 "aria-labelledby":"l_ticket1651"
119 };
120 (new dijit.form.TextBox(props, "ticket1651")).startup();
121
122 if(!test){ return; }
123
124 // Test initial conditions
125 doh.register("initial conditions", {
126 name: "initial conditions",
127 runTest: function(){
128 var form1 = dojo.byId("form1");
129
130 doh.is("Testing Testing", form1.firstname.value, "firstname");
131 doh.is("not fired yet!", dojo.byId("oc1").value, "firstname onchange");
132
133 doh.is("TESTING TESTING", form1.lastname.value, "lastname");
134
135 doh.is("", form1.age.value, "age");
136 doh.is("not fired yet!", dojo.byId("oc3").value, "age onchange");
137
138 doh.is("", form1.occupation.value, "occupation");
139
140 doh.is("3000", form1.elevation.value, "elevation");
141 doh.is("3,000", dojo.byId("q05").value, "elevation display value");
142 doh.is("not fired yet!", dojo.byId("oc5").value, "elevation onchange");
143 doh.t(!!dijit.byId("q05").constraints.allowCruft, "constructor constraints value");
144
145 doh.is("54775.53", form1.income1.value, "income1");
146 doh.is("$54,775.53", dojo.byId("q08").value, "income1 display value");
147 doh.is("not fired yet!", dojo.byId("oc8").value, "income1 onchange");
148
149 doh.is("54775.53", form1.income2.value, "income2");
150 doh.is("€54,775.53", dojo.byId("q08eur").value, "income2 display value");
151 doh.f(!!dijit.byId("q08eur").constraints.allowCruft, "constructor constraints value not proliferated");
152
153 doh.is("someTestString", form1.phone.value, "phone");
154 doh.is("", form1.password.value, "password");
155 doh.is("", form1.ticket1651.value, "ticket1651");
156 doh.is("cannot type here", form1.readOnly.value, "readonly");
157 doh.is("cannot type here", form1.disabled.value, "disabled");
158 }
159 });
160
161 var watchHandle, onChangeHandle;
162
163 function setTest(testName, textbox, setDict, watchExpected, unchangedExpected, isValid, onChangeExpected){
164 // summary:
165 // Generate test to call set("value", ...) and check response
166 // textbox: String
167 // id of TextBox widget
168 // setDict: Dictionary
169 // Value to pass to textbox.set(), such as {value: "123"} or {displayedValue: "1,234"}.
170 // watchExpected: Dictionary
171 // Expected changes in state of TextBox, such as
172 // {value: 1234, displayedValue: "1,234"}
173 // Checks that watch() returns these values.
174 // Also checks that textbox is actually displaying displayedValue
175 // unchangedExpected: Dictionary
176 // Attributes of textbox that shouldn't change/be reported by watch(), and their values
177 // {value: 1234, displayedValue: "1,234"}
178 // Checks that watch() returns these values.
179 // Also checks that textbox is actually displaying displayedValue
180 // isValid: Boolean
181 // Checks return of textbox.isValid(). TODO: this should be watchable.
182 // onChangeExpected:
183 // Check that onChange reports this value
184
185
186 return {
187 name: testName,
188 timeout: 1000,
189 runTest: function(){
190
191 textbox = dijit.byId(textbox);
192
193 // expectedState is a combination of the attributes that we expect to change
194 // and the attributes that we expect not to change
195 var expectedState = dojo.delegate(watchExpected, unchangedExpected);
196
197 // save all notifications from watch()
198 var watchActual = {};
199 watchHandle = textbox.watch(function(attr, oldVal, newVal){
200 console.log(textbox.id + ": " + attr + ": " + oldVal + " --> " + newVal);
201 watchActual[attr] = fixNbsp(newVal);
202 });
203
204 // and monitor onChange() calls too
205 var onChangeActual;
206 if(onChangeExpected){
207 onChangeHandle = textbox.on("change", function(newVal){
208 onChangeActual = fixNbsp(newVal);
209 });
210 }
211
212 // do the set
213 textbox.set(setDict);
214
215 doh.is(expectedState.displayedValue, fixNbsp(textbox.focusNode.value), "focusNode.value");
216
217 doh.is(isValid, textbox.isValid(), "isValid()");
218
219 var d = new doh.Deferred();
220
221 setTimeout(d.getTestCallback(function(){
222 // test that onChange() was called correctly
223 if(onChangeExpected){
224 doh.is(onChangeExpected, onChangeActual, "onChange()");
225 }
226
227 // check that watch() callbacks were called
228 for(attr in watchExpected){
229 doh.t(attr in watchActual, "watch(" + attr + ") fired");
230 doh.is(watchExpected[attr], watchActual[attr], "watch(" + attr + ")");
231 doh.is(typeof watchExpected[attr], typeof watchActual[attr], "typeof watch(" + attr + ")")
232 }
233
234 // check that direct get(...) calls are also working, for both the attributes
235 // that were supposed to change and the attributes that weren't supposed to change
236 for(attr in expectedState){
237 doh.is(expectedState[attr], fixNbsp(textbox.get(attr)), "get(" + attr + ")");
238 doh.is(typeof expectedState[attr], typeof textbox.get(attr), "typeof get(" + attr + ")")
239 }
240
241 // check that watch() didn't report attributes as changed when they didn't change
242 for(attr in unchangedExpected){
243 doh.f(attr in watchActual, attr + " shouldn't have been reported as changed by watch " +
244 watchActual[attr]);
245 }
246 }), 50);
247
248 return d;
249 },
250 tearDown: function(){
251 watchHandle.unwatch();
252 watchHandle = null;
253 if(onChangeHandle){
254 onChangeHandle.remove();
255 onChangeHandle = null;
256 }
257 }
258 };
259 }
260
261 doh.register("set('value')", [
262 // test valid and invalid settings of value
263 setTest("valid_max", 'q03', {value: 120}, {value: 120, displayedValue: "120"}, {}, true),
264 setTest("out_of_range_max",'q03', {value: 121}, {value: 121, displayedValue: "121", state: "Error"}, {}, false),
265 setTest("valid_min", 'q03', {value: 0}, {value: 0, displayedValue: "0", state: ""}, {}, true),
266 setTest("out_of_range_min", 'q03', {value: -1}, {value: -1, displayedValue: "-1", state: "Error"}, {}, false),
267 setTest("invalid", 'q03', {value: 'two'}, {value: undefined, displayedValue: 'two'}, {}, false),
268 setTest("null_required", 'q03', {required: true, value: null},
269 {required: true, value: NaN, displayedValue: ''}, {state: "Error"}, false),
270 setTest("null_notrequired", 'q03', {required: false, value: null}, {}, {displayedValue: ''}, true),
271
272 // test formatting of value vs. displayed value
273 setTest("number format", 'q05', {value: 1234}, {value: 1234, displayedValue: "1,234"}, {}, true),
274 setTest("currency format", 'q08', {value: 1234}, {value: 1234, displayedValue: "$1,234.00"}, {}, true)
275 ]);
276
277 doh.register("set('displayedValue')", [
278 // test formatting of value vs. displayed value, in reverse
279 setTest("number format", 'q05', {displayedValue: "4,321"}, {value: 4321, displayedValue: "4,321"}, {}, true),
280 setTest("european currency format", 'q08eurde', {displayedValue: "4.321,98"},
281 {value: 4321.98, displayedValue: "4.321,98 €"}, {}, true)
282 ]);
283
284 doh.register("font inheritance", [
285 {
286 name: "with srcNodeRef, style on .dijitTextBox",
287 runTest: function(){
288 var d = new doh.Deferred();
289 setTimeout(d.getTestCallback(function(){
290 doh.is("monospace", dojo.style('monospace1', "fontFamily"));
291 }), 0);
292 return d;
293 }
294 },
295 {
296 name: "without srcNodeRef, style on .dijitTextBox",
297 runTest: function(){
298 var d = new doh.Deferred();
299 setTimeout(d.getTestCallback(function(){
300 doh.is("monospace", dojo.style('monospace2', "fontFamily"));
301 }), 0);
302 return d;
303 }
304 },
305 {
306 name: "with srcNodeRef, style inherited",
307 runTest: function(){
308 var d = new doh.Deferred();
309 setTimeout(d.getTestCallback(function(){
310 doh.is("sans-serif", dojo.style('sans1', "fontFamily"));
311 }), 0);
312 return d;
313 }
314 },
315 {
316 name: "without srcNodeRef, style inherited",
317 runTest: function(){
318 var d = new doh.Deferred();
319 setTimeout(d.getTestCallback(function(){
320 doh.is("sans-serif", dojo.style('sans2', "fontFamily"));
321 }), 0);
322 return d;
323 }
324 }
325 ]);
326
327 doh.register("pattern", [
328 {
329 name: "pattern markup",
330 runTest: function(){
331 var w = dijit.byId('q22');
332 w.set('value', 'someTestString');
333 doh.is(true, w.isValid(false));
334 doh.f(!!w.focusNode.getAttribute('pattern'), "native pattern");
335 }
336 },
337 {
338 name: "pattern string",
339 runTest: function(){
340 var w = dijit.byId('q22');
341 w.set('value', 'someTestString');
342 w.set('pattern', "some[a-z]+"); // invalid
343 doh.is(false, w.isValid(false), "invalid");
344 doh.is(false, w._isValidSubset(), "invalid partial");
345 w.set('value', 'some');
346 doh.is(true, w._isValidSubset(), "valid partial");
347 w.set('value', 'someTestString');
348 w.set('pattern', "someT[a-z]+S[a-z]+"); // valid
349 doh.is(true, w.isValid(false), "valid");
350 doh.is(true, w._isValidSubset(), "valid partial 2");
351 doh.f(!!w.focusNode.getAttribute('pattern'), "native pattern");
352 }
353 },
354 {
355 name: "pattern function",
356 runTest: function(){
357 var w = dijit.byId('q22');
358 w.set('value', 'someTestString');
359 w.set('pattern', function(){ return "[a-z]+"; }); // invalid
360 doh.is('Error', w.get('state'));
361 doh.is(false, w.isValid(false), "invalid string");
362 w.set('pattern', function(){ return "[a-zTS]+"; }); // valid
363 doh.is('', w.get('state'));
364 doh.is(true, w.isValid(false), "valid string");
365 }
366 }
367 ]);
368
369 doh.register("#11889", [
370 {
371 name: "non-focused places:5",
372 timeout: 2000,
373 textbox: "q05",
374 setUp: function(){
375 this.textbox = dijit.byId(this.textbox);
376 this.textbox.set('constraints', { places: 5 });
377 this.textbox.set('editOptions', { places: "2,4" });
378 },
379 runTest: function(){
380 this.textbox.set('value', 1.625);
381 doh.is(1.625, this.textbox.get('value'), 'numeric value is unchanged');
382 doh.is('1.62500', this.textbox.get('displayedValue'), 'formatted displayed value');
383 doh.t(this.textbox.isValid(false), 'nonfocused is valid');
384 }
385 },
386 {
387 name: "focused places:2,4. blur to places:5",
388 timeout: 2000,
389 textbox: "q05",
390 runTest: function(){
391 var d = new doh.Deferred();
392 var textbox = this.textbox;
393
394 textbox = dijit.byId(this.textbox);
395 textbox.set('constraints', { places: 5 });
396 textbox.set('editOptions', { places: "2,4" });
397 textbox.focus();
398
399 setTimeout(d.getTestErrback(function(){ // allow time for async focus on IE9+
400 textbox.set('value', 1.125);
401
402 doh.is(1.125, textbox.get('value'), 'numeric value is unchanged');
403 doh.is('1.125', textbox.get('displayedValue'), 'formatted displayed value');
404 doh.t(textbox.isValid(true), 'focused is valid');
405
406
407 var handler = textbox.on("blur", function(){
408 handler.remove();
409 setTimeout(d.getTestCallback(function(){
410 doh.is(1.125, textbox.get('value'), 'numeric value is unchanged #2');
411 doh.is('1.12500', textbox.get('displayedValue'), 'formatted displayed value #2');
412 doh.t(textbox.isValid(false), 'nonfocused is valid #2');
413 }), 150);
414 });
415 dojo.byId("q01").focus();
416 }), 0);
417
418 return d;
419 }
420 }
421 ]);
422
423 doh.register("validation in dialog", [
424 {
425 name: "showDialog",
426 timeout: 5000,
427 runTest: function() {
428 // Show dialog, returning Deferred that fires when show dialog is finished.
429 // Before showing, focus the open button, so that Dialog knows where to return focus to.
430
431 var d = new doh.Deferred();
432
433 dijit.byId("dlgOpenBtn").focus();
434
435 // Focus on IE9+ is asynchronous, so wait for it to occur before showing Dialog. Otherwise,
436 // when Dialog closes it restores focus somewhere strange.
437 setTimeout(function () {
438 dijit.byId("dlg").show().then(function () {
439 d.resolve(true);
440 });
441 }, 0);
442
443 return d;
444 }
445 },
446 function enterInvalidValue(){
447 // Entering invalid value should make validation tooltip appear
448 var d = new doh.Deferred();
449 dijit.byId("dlgNTB").set("value", "invalid");
450 dijit.byId("dlgNTB").focus();
451 setTimeout(d.getTestCallback(function(){
452 masterTT = dojo.global.dijit._masterTT;
453 doh.t(masterTT && isVisible(masterTT.domNode), "tooltip shown");
454 }), 300);
455 return d;
456 },
457 {
458 name: "hideDialog",
459 timeout: 5000,
460 runTest: function () {
461 // Hiding the dialog should make the validation tooltip disappear
462 var d = new doh.Deferred();
463 dijit.byId("dlg").hide().then(function () {
464 setTimeout(d.getTestCallback(function () {
465 doh.t(isHidden(masterTT.domNode), "tooltip hidden");
466 }), 300);
467 });
468 return d;
469 }
470 }
471 ]);
472
473 doh.run();
474 });
475 </script>
476 </head>
477
478 <body class="claro" role="main">
479 <h1 class="testTitle">Dijit Validation Widgets</h1>
480 <!-- to test form submission, you'll need to create an action handler similar to
481 http://www.utexas.edu/teamweb/cgi-bin/generic.cgi -->
482 <form id="form1" action="" name="example" method="GET">
483
484 <div class="dojoTitlePaneLabel">
485 <label for="q01">First Name: </label>
486 <span class="noticeMessage"> TextBox class, <b>tabIndex=2</b>, Attributes: {trim: true, propercase: true, intermediateChanges: true, style: 'width:700px', selectOnClick: true}, First letter of each word is upper case.</span>
487 </div>
488 <div class="testExample">
489 <input id="q01" data-dojo-type="dijit/form/TextBox"
490 name="firstname" value="testing testing" style="width:700px" tabIndex="2"
491 data-dojo-props='
492 trim:true,
493 selectOnClick:true,
494 onFocus:function(){ console.log("user onfocus handler"); },
495 onBlur:function(){ console.log("user onblur handler"); },
496 onChange:function(v){ dojo.byId("oc1").value=v; },
497 intermediateChanges:true,
498 propercase:true '/>
499 <br><label for="oc1">onChange:</label><input id="oc1" size="34" disabled value="not fired yet!" autocomplete="off"/>
500 <input tabIndex="-1" type="button" onclick="dijit.byId('q01').set('disabled', true);" value="Disable"/>
501 <input tabIndex="-1" type="button" onclick="dijit.byId('q01').set('disabled', false);" value="Enable"/>
502 </div>
503
504 <div class="dojoTitlePaneLabel">
505 <label for="q02">Last Name: </label>
506 <span class="noticeMessage"> TextBox class, Attributes: {trim: true, uppercase: true, "class": 'verylong'}, all letters converted to upper case. </span>
507 </div>
508 <div class="testExample">
509 <input id="q02" data-dojo-type="dijit/form/TextBox"
510 name="lastname" value="testing testing" class="verylong"
511 data-dojo-props='trim:true, uppercase:true '/>
512 </div>
513
514 <div class="dojoTitlePaneLabel">
515 <label for="q03">Age: </label>
516 <span class="noticeMessage"> NumberTextBox class, <b>tabIndex=1</b>, Attributes: {trim: true}, no initial value specified, tooltipPosition=[above, below]. Displays a prompt message if field is blank.</span>
517 </div>
518 <div class="testExample">
519 <input id="q03" data-dojo-type="dijit/form/NumberTextBox"
520 name="age" tabIndex="1" class="small"
521 data-dojo-props='
522 promptMessage:"(optional) Enter an age between 0 and 120",
523 maxLength:"3",
524 constraints:{places:0,min:0,max:120},
525 onChange:function(val){ dojo.byId("oc3").value=""+val; },
526 tooltipPosition:["above", "below"]
527 '/>
528 <label for="oc3">onChange:</label><input id="oc3" size="14" disabled value="not fired yet!" autocomplete="off"/>
529 <span style='white-space:nowrap;'>
530 <button id="q03_valid" type=button onclick="dijit.byId('q03').set('value', 120);">set value to 120</button>
531 <button id="q03_outofrange" type=button onclick="dijit.byId('q03').set('value', 121);">set value to 121</button>
532 <button id="q03_invalid" type=button onclick="dijit.byId('q03').set('value', 'two');">set value to two</button>
533 <button id="q03_null" type=button onclick="dijit.byId('q03').set('value', null);">set value to null</button>
534 <button type=button onclick="dojo.byId('gv3').value=''+dijit.byId('q03').get('value');">get value</button>
535 <input id="gv3" aria-label="get value 3" size="10" disabled value="" autocomplete="off"/>
536 </span>
537 </div>
538
539 <div class="dojoTitlePaneLabel">
540 <label for="fav">Favorite Number (1-100): </label>
541 <span class="noticeMessage"> NumberTextBox class, Attributes: required=true, must be integer, no messages provided, no initial value specified, maxlength=3</span>
542 </div>
543 <div class="testExample">
544 <input id="fav" data-dojo-type="dijit/form/NumberTextBox"
545 name="fav" class="small" required
546 data-dojo-props='maxLength:"3",constraints:{places:0,min:1,max:100},pattern:"\\d+"'/>
547 <button onclick="dijit.byId('fav').set('required', true); return false;">attr(required, true)</button>
548 <button onclick="dijit.byId('fav').set('required', false); return false;">attr(required, false)</button>
549 </div>
550
551 <div class="dojoTitlePaneLabel">
552 <label for="q04">Occupation: </label>
553 <span class="noticeMessage">ValidationTextBox class,
554 Attributes: {lowercase: true, required: true, "class": verylong, style: font-size: 15pt;}. Displays a prompt message if field is blank.</span>
555 </div>
556 <div class="testExample">
557 <input id="q04" data-dojo-type="dijit/form/ValidationTextBox"
558 name="occupation" class="verylong" style="fontSize:15pt" required="true"
559 data-dojo-props='lowercase:true, promptMessage:"Enter an occupation" '/>
560 </div>
561
562 <div class="dojoTitlePaneLabel">
563 <label for="q05">Elevation: </label>
564 <span class="noticeMessage">IntegerTextBox class,
565 Attributes: {required: true, min:-20000, max:+20000 }, displays a prompt message if field is blank, thousands separator remains during editing.</span>
566 <span class="noticeMessage">Enter feet above sea level with a sign.</span>
567 </div>
568 <div class="testExample">
569 <input id="q05" class="small"/>
570 <label for="oc5">onChange:</label><input id="oc5" size="10" disabled value="not fired yet!" autocomplete="off"/>
571 </div>
572 <!--
573 <div class="dojoTitlePaneLabel">
574 <label for="attach-here">Population: </label>
575 <span class="noticeMessage">IntegerTextBox class,
576 Attributes: {trim: true, required: true, signed: false, separator: ","}. <br><b> This widget was added in script, not markup. </b> </span>
577 </div>
578 <div class="testExample" >
579 <input id="attach-here" type="text" name="population" class="medium" value="1500000"/>
580 </div>
581
582 <script>
583 // See if we can make a widget in script and attach it to the DOM ourselves.
584 dojo.ready(function(){
585 var props = {
586 name: "population",
587 value: "1,500,000",
588 trim: "true",
589 required: "true",
590 pattern: dojo.regexp.integer,
591 constraints: {signed:false, separator: ","},
592 invalidMessage: "Invalid population. Enter a number."
593 };
594 var w = new dijit.form.ValidationTextBox(props, "attach-here");
595 });
596 </script>
597
598 <div class="dojoTitlePaneLabel">
599 <label for="q06">Real Number: </label>
600 <span class="noticeMessage">RealNumberTextBox class,
601 Attributes: {trim: true, required: true}. Enter any sort of real number.</span>
602 </div>
603 <div class="testExample">
604 <input id="q06" type="text" name="real1" class="medium" value="+0.1234"
605 data-dojo-type="dijit/form/ValidationTextBox"
606 pattern="dojo.regexp.realNumber"
607 trim="true"
608 required="true"
609 invalidMessage="This is not a valid real number." />
610 </div>
611 <div class="dojoTitlePaneLabel">
612 <label for="q07">Exponential Notation: </label>
613 <span class="noticeMessage">RealNumberTextBox class,
614 Attributes: {exponent: true}. Enter a real number in exponential notation.</span>
615 </div>
616 <div class="testExample">
617 <input id="q07" type="text" name="real2" class="medium" value="+0.12"
618 data-dojo-type="dijit/form/ValidationTextBox"
619 pattern="dojo.regexp.realNumber"
620 trim="true"
621 required="true"
622 constraints="{exponent:true}"
623 invalidMessage="Number must be in exponential notation. Example +5E-28" />
624 </div>
625 -->
626
627 <div class="dojoTitlePaneLabel">
628 <label for="q08">Annual Income: </label>
629 <span class="noticeMessage">CurrencyTextBox class,
630 Attributes: {fractional: true}. Enter whole and cents. Currency symbol is optional. Cents are MANDATORY.</span>
631 </div>
632
633 <div class="testExample">
634 <input id="q08" data-dojo-type="dijit/form/CurrencyTextBox"
635 name="income1" class="medium" value="54775.53" required
636 data-dojo-props='constraints:{fractional:true},
637 currency:"USD",
638 onChange:function(val){ dojo.byId("oc8").value = val; },
639 invalidMessage:"Invalid amount. Cents are MANDATORY." '/>USD
640 &nbsp;<label for="oc8">onChange:</label><input id="oc8" size="15" disabled value="not fired yet!" autocomplete="off"/>
641 </div>
642
643 <div class="testExample">
644 <label for="q08eur">euro currency (local format) fractional part is optional:</label>
645 <input id="q08eur" data-dojo-type="dijit/form/CurrencyTextBox"
646 name="income2" class="medium" value="54775.53" required
647 data-dojo-props='currency:"EUR", invalidMessage:"Invalid amount. Include cents." '/>EUR
648 <button onclick="dijit.byId('q08eur').set('disabled',true); return false;">Disable</button>
649 <button onclick="dijit.byId('q08eur').set('disabled',false); return false;">Enable</button>
650 <button onclick="dijit.byId('q08eur').reset(); return false;">Reset</button>
651 </div>
652
653 <!--
654 It is unusual to override the lang properties on individual
655 widgets. Usually it should be the user's default or set on
656 a page basis by the server. This is for testing purposes
657 -->
658 <div class="testExample">
659 euro currency (fixed lang: de-de) programmatically created, fractional part is optional: <input id="q08eurde" class="medium"/>EUR
660 </div>
661
662 <script>
663 // See if we can make a widget in script and attach it
664 // to the DOM ourselves.
665 dojo.ready(function(){
666 var example = dojo.currency.format(54775.53, {locale: 'de-de', currency: "EUR"});
667 var props = {
668 name: "income3",
669 value: 54775.53,
670 lang: 'de-de',
671 required: true,
672 currency: "EUR",
673 invalidMessage: "Invalid amount. Example: " + example,
674 "aria-label": "income3 de-de"
675 };
676 var w = new dijit.form.CurrencyTextBox(props, "q08eurde");
677 });
678 </script>
679
680 <!--
681 <div class="dojoTitlePaneLabel">
682 <label for="q08a">Annual Income: </label>
683 <span class="noticeMessage">Old regexp currency textbox,
684 Attributes: {fractional: true}. Enter dollars and cents.</span>
685 </div>
686 <div class="testExample">
687 <input id="q08a" type="text" name="income3" class="medium" value="$54,775.53"
688 data-dojo-type="dijit/form/ValidationTextBox"
689 pattern="dojo.regexp.currency"
690 trim="true"
691 required="true"
692 constraints="{fractional:true}"
693 invalidMessage="Invalid amount. Include cents. Example: $12,000.00" />
694 </div>
695
696 <div class="dojoTitlePaneLabel">
697 <label for="q09">IPv4 Address: </label>
698 <span class="noticeMessage">IpAddressTextBox class,
699 Attributes: {allowIPv6: false, allowHybrid: false}. Also Dotted Hex works, 0x18.0x11.0x9b.0x28</span>
700 </div>
701 <div class="testExample">
702 <input id="q09" type="text" name="ipv4" class="medium" value="24.17.155.40"
703 data-dojo-type="dijit/form/ValidationTextBox"
704 pattern="dojo.regexp.ipAddress"
705 trim="true"
706 required="true"
707 constraints="{allowIPv6:false,allowHybrid:false}"
708 invalidMessage="Invalid IPv4 address."/>
709 </div>
710
711 <div class="dojoTitlePaneLabel">
712 <label for="q10"> IPv6 Address: </label>
713 <span class="noticeMessage">IpAddressTextBox class,
714 Attributes: {allowDottedDecimal: false, allowDottedHex: false}.
715 Also hybrid works, x:x:x:x:x:x:d.d.d.d</span>
716 </div>
717 <div class="testExample">
718 <input id="q10" type="text" name="ipv6" class="long" value="0000:0000:0000:0000:0000:0000:0000:0000"
719 data-dojo-type="dijit/form/ValidationTextBox"
720 pattern="dojo.regexp.ipAddress"
721 trim="true"
722 uppercase = "true"
723 required="true"
724 constraints="{allowDottedDecimal:false, allowDottedHex:false, allowDottedOctal:false}"
725 invalidMessage="Invalid IPv6 address, please enter eight groups of four hexadecimal digits. x:x:x:x:x:x:x:x"/>
726 </div>
727
728 <div class="dojoTitlePaneLabel">
729 <label for="q11"> URL: </label>
730 <span class="noticeMessage">UrlTextBox class,
731 Attributes: {required: true, trim: true, scheme: true}. </span>
732 </div>
733
734 <div class="testExample">
735 <input id="q11" type="text" name="url" class="long" value="http://www.xyz.com/a/b/c?x=2#p3"
736 data-dojo-type="dijit/form/ValidationTextBox"
737 pattern="dojo.regexp.url"
738 trim="true"
739 required="true"
740 constraints="{scheme:true}"
741 invalidMessage="Invalid URL. Be sure to include the scheme, http://..." />
742 </div>
743
744 <div class="dojoTitlePaneLabel">
745 <label for="q12"> Email Address </label>
746 <span class="noticeMessage">EmailTextBox class,
747 Attributes: {required: true, trim: true}. </span>
748 </div>
749
750 <div class="testExample">
751 <input id="q12" type="text" name="email" class="long" value="fred&[email protected]"
752 data-dojo-type="dijit/form/ValidationTextBox"
753 pattern="dojo.regexp.emailAddress"
754 trim="true"
755 required="true"
756 invalidMessage="Invalid Email Address." />
757 </div>
758
759 <div class="dojoTitlePaneLabel">
760 <label for="q13"> Email Address List </label>
761 <span class="noticeMessage">EmailListTextBox class,
762 Attributes: {required: true, trim: true}. </span>
763 </div>
764
765 <div class="testExample">
766 <input id="q13" type="text" name="email" class="long" value="[email protected]; [email protected]; [email protected]; "
767 data-dojo-type="dijit/form/ValidationTextBox"
768 pattern="dojo.regexp.emailAddressList"
769 trim="true"
770 required="true"
771 invalidMessage="Invalid Email Address List." />
772 </div>
773 -->
774 <div class="dojoTitlePaneLabel">
775 <label for="q22">Regular Expression </label>
776 <span class="noticeMessage">RegexpTextBox class,
777 Attributes: {required: true} </span>
778 </div>
779 <div class="testExample">
780 <input id="q22" data-dojo-type="dijit/form/ValidationTextBox"
781 name="phone" class="medium" value="someTestString" required
782 data-dojo-props='pattern:"[\\w]+", invalidMessage:"Invalid Non-Space Text."'/>
783 </div>
784
785 <div class="dojoTitlePaneLabel">
786 <label for="q23"> Password </label>
787 <span class="noticeMessage">(just a test that type attribute is obeyed) </span>
788 </div>
789 <div class="testExample">
790 <input id="q23" data-dojo-type="dijit/form/TextBox" type="password" name="password" class="medium"/>
791 </div>
792
793 <div class="dojoTitlePaneLabel">
794 <label id="l_ticket1651">Trac ticket 1651: </label>
795 <span class="noticeMessage">value: null should show up as empty</span>
796 </div>
797 <div class="testExample">
798 <input id="ticket1651" class="medium" value="not null"/>
799 </div>
800
801 <div class="dojoTitlePaneLabel">
802 <label for="q24">initially readOnly TextBox</label>
803 <span class="noticeMessage">a test that readOnly and disabled are understood for TextBox</span>
804 </div>
805 <div class="testExample">
806 <input id="q24" data-dojo-type="dijit/form/TextBox"
807 name="readOnly" class="medium" readOnly value="cannot type here" title="hint text"/>
808 <input type="button" id="removereadonly" onclick="dijit.byId('q24').set('readOnly',false);" value="Remove readOnly" tabIndex="-1"/>
809 <input type="button" onclick="dijit.byId('q24').set('readOnly',true);" value="Set readOnly" tabIndex="-1"/>
810 <input type="button" id="removedisabled" onclick="dijit.byId('q24').set('disabled',false);" value="Remove disabled" tabIndex="-1"/>
811 <input type="button" onclick="dijit.byId('q24').set('disabled',true);" value="Set disabled" tabIndex="-1"/>
812 </div>
813 <div class="dojoTitlePaneLabel">
814 <label for="q25">initially disabled ValidationTextBox</label>
815 <span class="noticeMessage">a test that disabled is understood for ValidationTextBox</span>
816 </div>
817 <div class="testExample">
818 <input id="q25" data-dojo-type="dijit/form/ValidationTextBox"
819 name="disabled" class="medium" disabled value="cannot type here"/>
820 <input type="button" onclick="dijit.byId('q25').set('readOnly',false);" value="Remove readOnly" tabIndex="-1"/>
821 <input type="button" onclick="dijit.byId('q25').set('readOnly',true);" value="Set readOnly" tabIndex="-1"/>
822 <input type="button" onclick="dijit.byId('q25').set('disabled',false);" value="Remove disabled" tabIndex="-1"/>
823 <input type="button" onclick="dijit.byId('q25').set('disabled',true);" value="Set disabled" tabIndex="-1"/>
824 </div>
825
826 <script>
827 // so robot can get to it easily
828 document.displayData=function(){
829 var f = document.getElementById("form1");
830 var s = "";
831 for(var i = 0; i < f.elements.length; i++){
832 var elem = f.elements[i];
833 if(elem.nodeName.toLowerCase() == "button" || elem.type=="submit" || elem.type=="button") { continue; }
834 s += elem.name + ": " + elem.value + "\n";
835 }
836 return s;
837 }
838 </script>
839
840 <div>
841 <button name="button" onclick="alert(document.displayData()); return false;" tabIndex="-1">view data</button>
842 <input type="submit" name="submit" tabIndex="-1"/>
843 </div>
844
845 </form>
846 <div class="dojoTitlePaneLabel">
847 <label for="q26">TextBox with placeholder</label>
848 <span class="noticeMessage">a test that placeholder works for TextBox. 10px padding added for testing.</span>
849 </div>
850 <div class="testExample">
851 <input id="q26" data-dojo-type="dijit/form/TextBox" placeHolder="placeholder is here" name="placeHolder" value=""/>
852 <button type="button" onclick="dijit.byId('q26').set('placeHolder', 'this is a very long placeholder that will overflow the input');">
853 set long placeholder
854 </button>
855 </div>
856 <h2>Tooltip positioning</h2>
857 <p>
858 These buttons switch the positions searched to try to place the validation error tooltips.
859 Note that setting tooltip positioning to "above" or "below" is dangerous if
860 you have a node with a dropdown, but the drop down might overlap the tooltip.
861 </p>
862 <button onclick="dijit.Tooltip.defaultPosition=['above', 'below'];">above, below</button>
863 <button onclick="dijit.Tooltip.defaultPosition=['after', 'before'];">after, before (default)</button>
864
865 <div class="monospace">
866 <input id="monospace1"/>
867 </div>
868 <div class="sans">
869 <input id="sans1"/>
870 </div>
871
872 <h2>Validation tooltips inside of dialogs:</h2>
873 <div dojoType="dijit.Dialog" id="dlg">
874 <label for="dlgNTB">NumberTextBox:</label>
875 <div dojoType="dijit.form.NumberTextBox" id="dlgNTB"></div>
876 </div>
877 <button dojoType="dijit.form.Button" id="dlgOpenBtn" onclick="dijit.byId('dlg').show();">show dialog</button>
878
879 <div class="dojoTitlePaneLabel">
880 <label id="l_ticket17923">Trac ticket 17923</label>
881 <span class="noticeMessage">Partial numeric input should be validated with respect to the min/max constraints and available space</span>
882 </div>
883
884 <div class="testExample">
885 <input id="ticket17923" class="medium"/>
886 <input type="button" id="ticket17923-maxLength5" value="maxLength: 5" tabIndex="-1"/>
887 <input type="button" id="ticket17923-maxLength3" value="maxLength: 3" tabIndex="-1"/>
888 <input type="button" id="ticket17923-min1:max15" value="min: 12, max: 142" tabIndex="-1"/>
889 <input type="button" id="ticket17923-min-15:max15" value="min: -15, max: -5" tabIndex="-1"/>
890 </div>
891 <script>
892 require(["dijit/form/NumberTextBox", "dojo/dom", "dojo/on", "dojo/_base/lang"], function(NumberTextBox, dom, on, lang){
893
894 var fld = new NumberTextBox({
895 name: "ticket17923",
896 constraints: {pattern: '#000.#', min: 12, max: 142 },
897 maxLength: 5
898 }, "ticket17923");
899
900 on(dom.byId("ticket17923-maxLength5"), 'click', function(){
901 fld.set('maxLength', 5);
902 });
903
904 on(dom.byId("ticket17923-maxLength3"), 'click', function(){
905 fld.set('maxLength', 3);
906 });
907
908 on(dom.byId("ticket17923-min1:max15"), 'click', function(){
909 fld.set('constraints', lang.mixin({}, fld.get('constraints'), {min: 12, max: 142}));
910 });
911
912 on(dom.byId("ticket17923-min-15:max15"), 'click', function(){
913 fld.set('constraints', lang.mixin({}, fld.get('constraints'), {min: -15, max: -5}));
914 });
915
916 fld.startup();
917 });
918 </script>
919
920 <div class="dojoTitlePaneLabel">
921 <label id="l_ticket17955">Trac ticket 17955</label>
922 <span class="noticeMessage">Ensure setting the formattedValue does not alter the entered value on blur</span>
923 </div>
924 <div class="testExample">
925 <input id="ticket17955" class="medium"/>
926 </div>
927 <script>
928 require(["dijit/form/NumberTextBox"], function(NumberTextBox){
929
930 var fld = new NumberTextBox({
931 name: "ticket17955",
932 constraints: {pattern: '000.#', min: 12, max: 142 },
933 placeHolder: "Number Pattern 000.#",
934 maxLength: 5
935 }, "ticket17955");
936 fld.startup();
937 });
938 </script>
939 <div class="dojoTitlePaneLabel">
940 <label id="l_ticket18260">Trac ticket 18260</label>
941 <span class="noticeMessage">Make sure rounding works with different locale's</span>
942 </div>
943
944 <div class="testExample">
945 <input id="ticket18260" class="medium"/>
946 </div>
947 <script>
948 require(["dijit/form/NumberTextBox"], function(NumberTextBox){
949
950 var fld = new NumberTextBox({
951 name: "ticket18260",
952 lang: 'de-de',
953 value: 12.4,
954 constraints: {pattern: '000.#', min: 12, max: 142 },
955 maxLength: 5
956 }, "ticket18260");
957 fld.startup();
958 });
959 </script>
960
961 <div class="dojoTitlePaneLabel">
962 <label id="l_ticket18367">Trac ticket 18367</label>
963 <span class="noticeMessage">Make sure precision ranges work as expected</span>
964 </div>
965 <div class="testExample">
966 <input id="ticket18367" class="medium"/>
967 </div>
968 <script>
969 require(["dijit/form/NumberTextBox"], function(NumberTextBox){
970
971 var fld = new NumberTextBox({
972 name: "ticket18367",
973 value: 8.0153234,
974 constraints: { min: 1, max: 10 , places: "0,5"},
975 maxLength: 5
976 }, "ticket18367");
977 fld.startup();
978 });
979 </script>
980
981 </body>
982 </html>