summaryrefslogtreecommitdiff
path: root/includes/js/dijit/tests/form/test_validate.html
blob: f6d1cdece953fac5ce7c76dcdd5c05ff2928c728 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
	"http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<title>Test TextBox Validation Widgets</title>

		<style type="text/css">
			@import "../../../dojo/resources/dojo.css";
			@import "../css/dijitTests.css";

			.testExample {
				background-color:#fbfbfb;
				padding:1em;
				margin-bottom:1em;
				border:1px solid #bfbfbf;
			}

			body .small {
				width: 3em;
			}
			body .medium {
				width: 10em;
			}
			body .long {
				width: 20em;
			}
			body .verylong {
				width: 90%;
			}

			.noticeMessage {
				color:#093669;
				font-size:0.95em;
				margin-left:0.5em;
			}

			.dojoTitlePaneLabel label {
				font-weight:bold;
			}
		</style>

		<script type="text/javascript" src="../../../dojo/dojo.js"
			djConfig="isDebug: true, parseOnLoad: true, extraLocale: ['de-de', 'en-us']"></script>
		<script type="text/javascript" src="../_testCommon.js"></script>

		<script type="text/javascript">
			dojo.require("dijit.form.TextBox");
			dojo.require("dijit.form.ValidationTextBox");
			dojo.require("dijit.form.NumberTextBox");
			dojo.require("dijit.form.CurrencyTextBox");
			dojo.require("dojo.currency");
			dojo.require("dojo.parser");	// scan page for widgets and instantiate them
		</script>
	</head>

	<body>
		<h1 class="testTitle">Dijit Validation Widgets</h1>
		<!--	to test form submission, you'll need to create an action handler similar to
			http://www.utexas.edu/teamweb/cgi-bin/generic.cgi -->
		<form id="form1" action="" name="example" method="">

			<div class="dojoTitlePaneLabel">
				<label for="q01">First Name:  </label>
				<span class="noticeMessage"> TextBox class, <b>tabIndex=2</b>, Attributes: {trim: true, propercase: true, style: 'width:700px'}, First letter of each word is upper case.</span>
			</div>
			<div class="testExample">
				<input id="q01" type="text" name="firstname" value="testing testing" style="width: 700px;" tabIndex=2
					dojoType="dijit.form.TextBox"
					trim="true"
					onfocus="console.log('user onfocus handler')"
					onblur="console.log('user onblur handler')"
				        onChange="dojo.byId('oc1').value=arguments[0]"
					propercase="true" />
				<br>onChange:<input id="oc1" size="34" disabled value="not fired yet!" autocomplete="off">
			</div>

			<div class="dojoTitlePaneLabel">
				<label for="q02">Last Name:  </label>
				<span class="noticeMessage"> TextBox class, Attributes: {trim: true, uppercase: true, class: 'verylong'}, all letters converted to upper case. </span>
			</div>
			<div class="testExample">
				<input id="q02" type="text" name="lastname" value="testing testing" class="verylong"
					dojoType="dijit.form.TextBox"
					trim="true"
					uppercase="true" />
			</div>

			<div class="dojoTitlePaneLabel">
				<label for="q03">Age:  </label>
				<span class="noticeMessage"> NumberTextBox class, <b>tabIndex=1</b>, Attributes: {trim: true}, no initial value specified, tooltipPosition=[above, below]</span>
			</div>
			<div class="testExample">
				<input id="q03" type="text" name="age" tabIndex=1
					dojoType="dijit.form.NumberTextBox"
					promptMessage="(optional) Enter an age between 0 and 120"
					maxLength="3"
					class="small"
					constraints="{places:0,min:0,max:120}"
					onChange="console.debug('onChange fired for widget id = ' + this.id + ' with value = ' + arguments[0]);"
					tooltipPosition="above, below"
					/>
			</div>

			<div class="dojoTitlePaneLabel">
				<label for="q04">Occupation:  </label>
				<span class="noticeMessage">ValidationTextBox class,
					Attributes: {lowercase: true, required: true, class: verylong, style: font-size: 15pt;}. Displays a prompt message if field is missing.</span>
			</div>
			<div class="testExample">
				<input id="q04" type="text" name="occupation" class="verylong" style="font-size:15pt;"
					dojoType="dijit.form.ValidationTextBox"
					lowercase="true"
					required="true"
					promptMessage="Enter an occupation" />
			</div>

			<div class="dojoTitlePaneLabel">
				<label for="q05">Elevation:  </label>
				<span class="noticeMessage">IntegerTextBox class,
					Attributes: {required: true, min:-20000, max:+20000 }, Enter feet above sea level with a sign.</span>
			</div>
			<div class="testExample">
				<input id="q05" class="small"/>
				onChange:<input id="oc5" size="10" disabled value="not fired yet!" autocomplete="off">
			</div>
<script>
	// See if we can make a widget in script and attach it to the DOM ourselves.
	dojo.addOnLoad(function(){
		var props = {
			name: "elevation",
			value: 3000,
			constraints: {min:-20000,max:20000,places:0},
			promptMessage: "Enter a value between -20000 and +20000",
			required: "true" ,
			invalidMessage: "Invalid elevation.",
			onChange: function(){dojo.byId('oc5').value=arguments[0]},
			"class": "medium"
		};
		var w = new dijit.form.NumberTextBox(props, "q05");
	});
</script>
<!--
			<div class="dojoTitlePaneLabel">
				<label for="attach-here">Population:  </label>
				<span class="noticeMessage">IntegerTextBox class,
					Attributes: {trim: true, required: true, signed: false, separator: ","}. <br><b> This widget was added in script, not markup. </b> </span>
			</div>
			<div class="testExample" >
				<input id="attach-here" type="text" name="population" class="medium" value="1500000"/>
			</div>

			<script>
				// See if we can make a widget in script and attach it to the DOM ourselves.
				dojo.addOnLoad(function(){
					var props = {
						name: "population",
						value: "1,500,000",
						trim: "true",
						required: "true",
						regExpGen: dojo.regexp.integer,
						constraints: {signed:false, separator: ","},
						invalidMessage: "Invalid population.  Be sure to use commas."
					};
					var w = new dijit.form.ValidationTextBox(props, "attach-here");
					});
			</script>

			<div class="dojoTitlePaneLabel">
				<label for="q06">Real Number:  </label>
				<span class="noticeMessage">RealNumberTextBox class,
					Attributes: {trim: true, required: true}. Enter any sort of real number.</span>
			</div>
			<div class="testExample">
				<input id="q06" type="text" name="real1" class="medium" value="+0.1234"
					dojoType="dijit.form.ValidationTextBox"
					regExpGen="dojo.regexp.realNumber"
					trim="true"
					required="true"
					invalidMessage="This is not a valid real number." />
			</div>
			<div class="dojoTitlePaneLabel">
				<label for="q07">Exponential Notation:  </label>
				<span class="noticeMessage">RealNumberTextBox class,
					Attributes: {exponent: true}. Enter a real number in exponential notation.</span>
			</div>
			<div class="testExample">
				<input id="q07" type="text" name="real2" class="medium" value="+0.12"
					dojoType="dijit.form.ValidationTextBox"
					regExpGen="dojo.regexp.realNumber"
					trim="true"
					required="true"
					constraints={exponent:true}
					invalidMessage="Number must be in exponential notation. Example +5E-28" />
			</div>
			-->
		
			<div class="dojoTitlePaneLabel">
				<label for="q08">Annual Income:  </label>
				<span class="noticeMessage">CurrencyTextBox class,
					Attributes: {fractional: true}.  Enter whole and cents.  Currency symbol is optional.</span>
			</div>
		
			<div class="testExample">
				<input id="q08" type="text" name="income1" class="medium" value="54775.53"
					dojoType="dijit.form.CurrencyTextBox"
					required="true"
					constraints="{fractional:true}"
					currency="USD"
				        onChange="dojo.byId('oc8').value=arguments[0]"
					invalidMessage="Invalid amount.  Include dollar sign, commas, and cents.  Cents are mandatory." />USD
				&nbsp;onChange:<input id="oc8" size="15" disabled value="not fired yet!" autocomplete="off">
			</div>
		
			<div class="testExample">
				euro currency (local format) fractional part is optional:
				<input id="q08eur" type="text" name="income2"
					class="medium" value="54775.53"
					dojoType="dijit.form.CurrencyTextBox"
					required="true"
					currency="EUR"
					invalidMessage="Invalid amount.  Include dollar sign, commas, and cents." />EUR
				<button onclick="dijit.byId('q08eur').setAttribute('disabled',true);return false">Disable</button>
				<button onclick="dijit.byId('q08eur').setAttribute('disabled',false);return false">Enable</button>
				<button onclick="dijit.byId('q08eur').reset();return false">Reset</button>
			</div>
		
			<!--
				It is unusual to override the lang properties on individual
				widgets.  Usually it should be the user's default or set on
				a page basis by the server.  This is for testing purposes
			-->
			<div class="testExample">
				euro currency (fixed lang: de-de) programmatically created, fractional part is optional: <input id="q08eurde" class="medium"/>EUR
			</div>
		
			<script>
				// See if we can make a widget in script and attach it
				// to the DOM ourselves.
				dojo.addOnLoad(function(){
					var example = dojo.currency.format(54775.53, {locale: 'de-de', currency: "EUR"});
					var props = {
						name: "income3",
						value: 54775.53,
						lang: 'de-de',
						required: "true",
						currency: "EUR",
						invalidMessage: "Invalid amount.  Example: " + example
					};
					var w = new dijit.form.CurrencyTextBox(props, "q08eurde");
				});
			</script>
		
			<!--
			<div class="dojoTitlePaneLabel">
				<label for="q08a">Annual Income:  </label>
				<span class="noticeMessage">Old regexp currency textbox,
							Attributes: {fractional: true}. Enter dollars and cents.</span>
			</div>
			<div class="testExample">
				<input id="q08a" type="text" name="income3" class="medium" value="$54,775.53"
					dojoType="dijit.form.ValidationTextBox"
					regExpGen="dojo.regexp.currency"
					trim="true"
					required="true"
					constraints={fractional:true}
					invalidMessage="Invalid amount.  Include dollar sign, commas, and cents. Example: $12,000.00" />
			</div>
		
			<div class="dojoTitlePaneLabel">
				<label for="q09">IPv4 Address:  </label>
				<span class="noticeMessage">IpAddressTextBox class,
					Attributes: {allowIPv6: false, allowHybrid: false}. Also Dotted Hex works, 0x18.0x11.0x9b.0x28</span>
			</div>
			<div class="testExample">
				<input id="q09" type="text" name="ipv4" class="medium" value="24.17.155.40"
					dojoType="dijit.form.ValidationTextBox"
					regExpGen="dojo.regexp.ipAddress"
					trim="true"
					required="true"
					constraints={allowIPv6:false,allowHybrid:false}
					invalidMessage="Invalid IPv4 address.">
			</div>
		
			<div class="dojoTitlePaneLabel">
				<label for="q10"> IPv6 Address:  </label>
				<span class="noticeMessage">IpAddressTextBox class,
					Attributes: {allowDottedDecimal: false, allowDottedHex: false}.
							Also hybrid works, x:x:x:x:x:x:d.d.d.d</span>
			</div>
			<div class="testExample">
				<input id="q10" type="text" name="ipv6" class="long" value="0000:0000:0000:0000:0000:0000:0000:0000"
					dojoType="dijit.form.ValidationTextBox"
					regExpGen="dojo.regexp.ipAddress"
					trim="true"
					uppercase = "true"
					required="true"
					constraints={allowDottedDecimal:false, allowDottedHex:false, allowDottedOctal:false}
					invalidMessage="Invalid IPv6 address, please enter eight groups of four hexadecimal digits. x:x:x:x:x:x:x:x">
			</div>
		
			<div class="dojoTitlePaneLabel">
				<label for="q11"> URL:  </label>
				<span class="noticeMessage">UrlTextBox class,
					Attributes: {required: true, trim: true, scheme: true}. </span>
			</div>
		
			<div class="testExample">
				<input id="q11" type="text" name="url" class="long" value="http://www.xyz.com/a/b/c?x=2#p3"
					dojoType="dijit.form.ValidationTextBox"
					regExpGen="dojo.regexp.url"
					trim="true"
					required="true"
					constraints={scheme:true}
					invalidMessage="Invalid URL.  Be sure to include the scheme, http://..." />
			</div>
		
			<div class="dojoTitlePaneLabel">
				<label for="q12"> Email Address  </label>
				<span class="noticeMessage">EmailTextBox class,
					Attributes: {required: true, trim: true}. </span>
			</div>
		
			<div class="testExample">
				<input id="q12" type="text" name="email" class="long" value="fred&barney@stonehenge.com"
					dojoType="dijit.form.ValidationTextBox"
					regExpGen="dojo.regexp.emailAddress"
					trim="true"
					required="true"
					invalidMessage="Invalid Email Address." />
			</div>
		
			<div class="dojoTitlePaneLabel">
				<label for="q13"> Email Address List </label>
				<span class="noticeMessage">EmailListTextBox class,
					Attributes: {required: true, trim: true}. </span>
			</div>
		
			<div class="testExample">
				<input id="q13" type="text" name="email" class="long" value="a@xyz.com; b@xyz.com; c@xyz.com; "
					dojoType="dijit.form.ValidationTextBox"
					regExpGen="dojo.regexp.emailAddressList"
					trim="true"
					required="true"
					invalidMessage="Invalid Email Address List." />
			</div>
			-->
			<div class="dojoTitlePaneLabel">
				<label for="q22">Regular Expression </label>
				<span class="noticeMessage">RegexpTextBox class,
					Attributes: {required: true} </span>
			</div>
			<div class="testExample">
				<input id="q22" type="text" name="phone" class="medium" value="someTestString"
					dojoType="dijit.form.ValidationTextBox"
					regExp="[\w]+"
					required="true"
					invalidMessage="Invalid Non-Space Text.">
			</div>
		
			<div class="dojoTitlePaneLabel">
				<label for="q23"> Password </label>
				<span class="noticeMessage">(just a test that type attribute is obeyed) </span>
			</div>
			<div class="testExample">
				<input id="q23" type="password" name="password" class="medium"
					dojoType="dijit.form.TextBox">
			</div>
		
			<div class="dojoTitlePaneLabel">
				<label for="ticket1651">Trac ticket 1651:  </label>
				<span class="noticeMessage">value: null should show up as empty</span>
			</div>
			<div class="testExample">
				<input id="ticket1651" class="medium" value="not null"/>
			</div>

			<script>
					// See if we can make a widget in script and attach it to the DOM ourselves.
					dojo.addOnLoad(function(){
							var props = {
									name: "ticket1651",
									id: "mname",
									value: null
							};
							var w = new dijit.form.TextBox(props, "ticket1651");
					});
			</script>

			<div class="dojoTitlePaneLabel">
				<label for="q24">readOnly test</label>
				<span class="noticeMessage">a test that readOnly is understood</span>
			</div>
			<div class="testExample">
				<input id="q24" type="text" name="readOnly" class="medium" readOnly value="cannot type here"
					dojoType="dijit.form.TextBox">
				<input type="button" onclick="dijit.byId('q24').setAttribute('readOnly',false);" value="Remove readOnly">
				<input type="button" onclick="dijit.byId('q24').setAttribute('readOnly',true);" value="Set readOnly">
			</div>

			<script>
				function displayData() {
					var f = document.getElementById("form1");
					var s = "";
					for (var i = 0; i < f.elements.length; i++) {
						var elem = f.elements[i];
						if (elem.name == "button")  { continue; }
						s += elem.name+(elem.name && elem.disabled?' (disabled)':'') + ": " + elem.value + "\n";
					}
					alert(s);
				}
			</script>

			<div>
				<button name="button" onclick="displayData(); return false;">view data</button>
				<input type="submit" name="submit" />
			</div>

		</form>
		<h2>Tooltip positioning</h2>
		<p>
		These buttons switch the positions searched to try to place the validation error tooltips.
		Note that setting tooltip positioning to "above" or "below" is dangerous if
		you have a node with a dropdown, but the drop down might overlap the tooltip.
		</p>
		<button onclick="dijit.Tooltip.defaultPosition=['above', 'below'];">above, below</button>
		<button onclick="dijit.Tooltip.defaultPosition=['after', 'before'];">after, before (default)</button>
	</body>
</html>