2150 |
mathias |
1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
|
|
2 |
"http://www.w3.org/TR/html4/strict.dtd">
|
|
|
3 |
<html>
|
|
|
4 |
<head>
|
|
|
5 |
<title>Test TextBox Validation Widgets</title>
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
<script type="text/javascript" src="../../../dojo/dojo.js"
|
|
|
9 |
djConfig="isDebug: true, parseOnLoad: true, extraLocale: ['de-de', 'en-us']"></script>
|
|
|
10 |
<script type="text/javascript" src="../_testCommon.js"></script>
|
|
|
11 |
|
|
|
12 |
<script type="text/javascript">
|
|
|
13 |
dojo.require("dijit.form.TextBox");
|
|
|
14 |
dojo.require("dijit.form.ValidationTextBox");
|
|
|
15 |
dojo.require("dijit.form.NumberTextBox");
|
|
|
16 |
dojo.require("dijit.form.CurrencyTextBox");
|
|
|
17 |
dojo.require("dojo.currency");
|
|
|
18 |
dojo.require("dojo.parser"); // scan page for widgets and instantiate them
|
|
|
19 |
</script>
|
|
|
20 |
<style type="text/css">
|
|
|
21 |
@import "../../../dojo/resources/dojo.css";
|
|
|
22 |
@import "../css/dijitTests.css";
|
|
|
23 |
|
|
|
24 |
.testExample {
|
|
|
25 |
background-color:#fbfbfb;
|
|
|
26 |
padding:1em;
|
|
|
27 |
margin-bottom:1em;
|
|
|
28 |
border:1px solid #bfbfbf;
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
.small {
|
|
|
32 |
width: 3em;
|
|
|
33 |
}
|
|
|
34 |
.medium {
|
|
|
35 |
width: 10em;
|
|
|
36 |
}
|
|
|
37 |
.long {
|
|
|
38 |
width: 20em;
|
|
|
39 |
}
|
|
|
40 |
.verylong {
|
|
|
41 |
width: 90%;
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
.noticeMessage {
|
|
|
45 |
color:#093669;
|
|
|
46 |
font-size:0.95em;
|
|
|
47 |
margin-left:0.5em;
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
.dojoTitlePaneLabel label {
|
|
|
51 |
font-weight:bold;
|
|
|
52 |
}
|
|
|
53 |
</style>
|
|
|
54 |
</head>
|
|
|
55 |
|
|
|
56 |
<body>
|
|
|
57 |
<h1 class="testTitle">Dijit Validation Widgets</h1>
|
|
|
58 |
<!-- to test form submission, you'll need to create an action handler similar to
|
|
|
59 |
http://www.utexas.edu/teamweb/cgi-bin/generic.cgi -->
|
|
|
60 |
<form id="form1" action="" name="example" method="post">
|
|
|
61 |
|
|
|
62 |
<div class="dojoTitlePaneLabel">
|
|
|
63 |
<label for="q01">First Name: </label>
|
|
|
64 |
<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>
|
|
|
65 |
</div>
|
|
|
66 |
<div class="testExample">
|
|
|
67 |
<input id="q01" type="text" name="firstname" value="testing testing" style="width: 700px;" tabIndex=2
|
|
|
68 |
dojoType="dijit.form.TextBox"
|
|
|
69 |
trim="true"
|
|
|
70 |
onChange="dojo.byId('oc1').value=arguments[0]"
|
|
|
71 |
propercase="true" />
|
|
|
72 |
<br>onChange:<input id="oc1" size="34" disabled value="not fired yet!" autocomplete="off">
|
|
|
73 |
</div>
|
|
|
74 |
|
|
|
75 |
<div class="dojoTitlePaneLabel">
|
|
|
76 |
<label for="q02">Last Name: </label>
|
|
|
77 |
<span class="noticeMessage"> TextBox class, Attributes: {trim: true, uppercase: true, class: 'verylong'}, all letters converted to upper case. </span>
|
|
|
78 |
</div>
|
|
|
79 |
<div class="testExample">
|
|
|
80 |
<input id="q02" type="text" name="lastname" value="testing testing" class="verylong"
|
|
|
81 |
dojoType="dijit.form.TextBox"
|
|
|
82 |
trim="true"
|
|
|
83 |
uppercase="true" />
|
|
|
84 |
</div>
|
|
|
85 |
|
|
|
86 |
<div class="dojoTitlePaneLabel">
|
|
|
87 |
<label for="q03">Age: </label>
|
|
|
88 |
<span class="noticeMessage"> NumberTextBox class, <b>tabIndex=1</b>, Attributes: {trim: true}, no initial value specified.</span>
|
|
|
89 |
</div>
|
|
|
90 |
<div class="testExample">
|
|
|
91 |
<input id="q03" type="text" name="age" tabIndex=1
|
|
|
92 |
dojoType="dijit.form.NumberTextBox"
|
|
|
93 |
promptMessage="(optional) Enter an age between 0 and 120"
|
|
|
94 |
maxLength=3
|
|
|
95 |
class="small"
|
|
|
96 |
constraints="{places:0,min:0,max:120}"
|
|
|
97 |
onChange="console.debug('onChange fired for widget id = ' + this.id + ' with value = ' + arguments[0]);"
|
|
|
98 |
/>
|
|
|
99 |
</div>
|
|
|
100 |
|
|
|
101 |
<div class="dojoTitlePaneLabel">
|
|
|
102 |
<label for="q04">Occupation: </label>
|
|
|
103 |
<span class="noticeMessage">ValidationTextBox class,
|
|
|
104 |
Attributes: {lowercase: true, required: true, class: verylong, style: font-size: 15pt;}. Displays a prompt message if field is missing.</span>
|
|
|
105 |
</div>
|
|
|
106 |
<div class="testExample">
|
|
|
107 |
<input id="q04" type="text" name="occupation" class="verylong" style="font-size:15pt;"
|
|
|
108 |
dojoType="dijit.form.ValidationTextBox"
|
|
|
109 |
lowercase="true"
|
|
|
110 |
required="true"
|
|
|
111 |
promptMessage="Enter an occupation" />
|
|
|
112 |
</div>
|
|
|
113 |
|
|
|
114 |
<div class="dojoTitlePaneLabel">
|
|
|
115 |
<label for="q05">Elevation: </label>
|
|
|
116 |
<span class="noticeMessage">IntegerTextBox class,
|
|
|
117 |
Attributes: {required: true, min:-20000, max:+20000 }, Enter feet above sea level with a sign.</span>
|
|
|
118 |
</div>
|
|
|
119 |
<div class="testExample">
|
|
|
120 |
<input id="q05" class="small"/>
|
|
|
121 |
onChange:<input id="oc5" size="10" disabled value="not fired yet!" autocomplete="off">
|
|
|
122 |
</div>
|
|
|
123 |
<script>
|
|
|
124 |
// See if we can make a widget in script and attach it to the DOM ourselves.
|
|
|
125 |
dojo.addOnLoad(function(){
|
|
|
126 |
var props = {
|
|
|
127 |
name: "elevation",
|
|
|
128 |
value: 3000,
|
|
|
129 |
constraints: {min:-20000,max:20000,places:0},
|
|
|
130 |
promptMessage: "Enter a value between -20000 and +20000",
|
|
|
131 |
required: "true" ,
|
|
|
132 |
invalidMessage: "Invalid elevation.",
|
|
|
133 |
onChange: function(){dojo.byId('oc5').value=arguments[0]},
|
|
|
134 |
"class": "medium"
|
|
|
135 |
};
|
|
|
136 |
var w = new dijit.form.NumberTextBox(props, "q05");
|
|
|
137 |
});
|
|
|
138 |
</script>
|
|
|
139 |
<!--
|
|
|
140 |
<div class="dojoTitlePaneLabel">
|
|
|
141 |
<label for="attach-here">Population: </label>
|
|
|
142 |
<span class="noticeMessage">IntegerTextBox class,
|
|
|
143 |
Attributes: {trim: true, required: true, signed: false, separator: ","}. <br><b> This widget was added in script, not markup. </b> </span>
|
|
|
144 |
</div>
|
|
|
145 |
<div class="testExample" >
|
|
|
146 |
<input id="attach-here" type="text" name="population" class="medium" value="1500000"/>
|
|
|
147 |
</div>
|
|
|
148 |
|
|
|
149 |
<script>
|
|
|
150 |
// See if we can make a widget in script and attach it to the DOM ourselves.
|
|
|
151 |
dojo.addOnLoad(function(){
|
|
|
152 |
var props = {
|
|
|
153 |
name: "population",
|
|
|
154 |
value: "1,500,000",
|
|
|
155 |
trim: "true",
|
|
|
156 |
required: "true",
|
|
|
157 |
regExpGen: dojo.regexp.integer,
|
|
|
158 |
constraints: {signed:false, separator: ","},
|
|
|
159 |
invalidMessage: "Invalid population. Be sure to use commas."
|
|
|
160 |
};
|
|
|
161 |
var w = new dijit.form.ValidationTextBox(props, "attach-here");
|
|
|
162 |
});
|
|
|
163 |
</script>
|
|
|
164 |
|
|
|
165 |
<div class="dojoTitlePaneLabel">
|
|
|
166 |
<label for="q06">Real Number: </label>
|
|
|
167 |
<span class="noticeMessage">RealNumberTextBox class,
|
|
|
168 |
Attributes: {trim: true, required: true}. Enter any sort of real number.</span>
|
|
|
169 |
</div>
|
|
|
170 |
<div class="testExample">
|
|
|
171 |
<input id="q06" type="text" name="real1" class="medium" value="+0.1234"
|
|
|
172 |
dojoType="dijit.form.ValidationTextBox"
|
|
|
173 |
regExpGen="dojo.regexp.realNumber"
|
|
|
174 |
trim="true"
|
|
|
175 |
required="true"
|
|
|
176 |
invalidMessage="This is not a valid real number." />
|
|
|
177 |
</div>
|
|
|
178 |
<div class="dojoTitlePaneLabel">
|
|
|
179 |
<label for="q07">Exponential Notation: </label>
|
|
|
180 |
<span class="noticeMessage">RealNumberTextBox class,
|
|
|
181 |
Attributes: {exponent: true}. Enter a real number in exponential notation.</span>
|
|
|
182 |
</div>
|
|
|
183 |
<div class="testExample">
|
|
|
184 |
<input id="q07" type="text" name="real2" class="medium" value="+0.12"
|
|
|
185 |
dojoType="dijit.form.ValidationTextBox"
|
|
|
186 |
regExpGen="dojo.regexp.realNumber"
|
|
|
187 |
trim="true"
|
|
|
188 |
required="true"
|
|
|
189 |
constraints={exponent:true}
|
|
|
190 |
invalidMessage="Number must be in exponential notation. Example +5E-28" />
|
|
|
191 |
</div>
|
|
|
192 |
-->
|
|
|
193 |
|
|
|
194 |
<div class="dojoTitlePaneLabel">
|
|
|
195 |
<label for="q08">Annual Income: </label>
|
|
|
196 |
<span class="noticeMessage">CurrencyTextBox class,
|
|
|
197 |
Attributes: {fractional: true}. Enter whole and cents. Currency symbol is optional.</span>
|
|
|
198 |
</div>
|
|
|
199 |
|
|
|
200 |
<div class="testExample">
|
|
|
201 |
<input id="q08" type="text" name="income1" class="medium" value="54775.53"
|
|
|
202 |
dojoType="dijit.form.CurrencyTextBox"
|
|
|
203 |
required="true"
|
|
|
204 |
constraints="{fractional:true}"
|
|
|
205 |
currency="USD"
|
|
|
206 |
onChange="dojo.byId('oc8').value=arguments[0]"
|
|
|
207 |
invalidMessage="Invalid amount. Include dollar sign, commas, and cents. Cents are mandatory." />USD
|
|
|
208 |
onChange:<input id="oc8" size="15" disabled value="not fired yet!" autocomplete="off">
|
|
|
209 |
</div>
|
|
|
210 |
|
|
|
211 |
<div class="testExample">
|
|
|
212 |
euro currency (local format) fractional part is optional:
|
|
|
213 |
<input id="q08eur" type="text" name="income2"
|
|
|
214 |
class="medium" value="54775.53"
|
|
|
215 |
dojoType="dijit.form.CurrencyTextBox"
|
|
|
216 |
required="true"
|
|
|
217 |
currency="EUR"
|
|
|
218 |
invalidMessage="Invalid amount. Include dollar sign, commas, and cents." />EUR
|
|
|
219 |
</div>
|
|
|
220 |
|
|
|
221 |
<!--
|
|
|
222 |
It is unusual to override the lang properties on individual
|
|
|
223 |
widgets. Usually it should be the user's default or set on
|
|
|
224 |
a page basis by the server. This is for testing purposes
|
|
|
225 |
-->
|
|
|
226 |
<div class="testExample">
|
|
|
227 |
euro currency (fixed lang: de-de) programmatically created, fractional part is optional: <input id="q08eurde" class="medium"/>EUR
|
|
|
228 |
</div>
|
|
|
229 |
|
|
|
230 |
<script>
|
|
|
231 |
// See if we can make a widget in script and attach it
|
|
|
232 |
// to the DOM ourselves.
|
|
|
233 |
dojo.addOnLoad(function(){
|
|
|
234 |
var example = dojo.currency.format(54775.53, {locale: 'de-de', currency: "EUR"});
|
|
|
235 |
var props = {
|
|
|
236 |
name: "income3",
|
|
|
237 |
value: 54775.53,
|
|
|
238 |
lang: 'de-de',
|
|
|
239 |
required: "true",
|
|
|
240 |
currency: "EUR",
|
|
|
241 |
invalidMessage: "Invalid amount. Example: " + example
|
|
|
242 |
};
|
|
|
243 |
var w = new dijit.form.CurrencyTextBox(props, "q08eurde");
|
|
|
244 |
});
|
|
|
245 |
</script>
|
|
|
246 |
|
|
|
247 |
<!--
|
|
|
248 |
<div class="dojoTitlePaneLabel">
|
|
|
249 |
<label for="q08a">Annual Income: </label>
|
|
|
250 |
<span class="noticeMessage">Old regexp currency textbox,
|
|
|
251 |
Attributes: {fractional: true}. Enter dollars and cents.</span>
|
|
|
252 |
</div>
|
|
|
253 |
<div class="testExample">
|
|
|
254 |
<input id="q08a" type="text" name="income3" class="medium" value="$54,775.53"
|
|
|
255 |
dojoType="dijit.form.ValidationTextBox"
|
|
|
256 |
regExpGen="dojo.regexp.currency"
|
|
|
257 |
trim="true"
|
|
|
258 |
required="true"
|
|
|
259 |
constraints={fractional:true}
|
|
|
260 |
invalidMessage="Invalid amount. Include dollar sign, commas, and cents. Example: $12,000.00" />
|
|
|
261 |
</div>
|
|
|
262 |
|
|
|
263 |
<div class="dojoTitlePaneLabel">
|
|
|
264 |
<label for="q09">IPv4 Address: </label>
|
|
|
265 |
<span class="noticeMessage">IpAddressTextBox class,
|
|
|
266 |
Attributes: {allowIPv6: false, allowHybrid: false}. Also Dotted Hex works, 0x18.0x11.0x9b.0x28</span>
|
|
|
267 |
</div>
|
|
|
268 |
<div class="testExample">
|
|
|
269 |
<input id="q09" type="text" name="ipv4" class="medium" value="24.17.155.40"
|
|
|
270 |
dojoType="dijit.form.ValidationTextBox"
|
|
|
271 |
regExpGen="dojo.regexp.ipAddress"
|
|
|
272 |
trim="true"
|
|
|
273 |
required="true"
|
|
|
274 |
constraints={allowIPv6:false,allowHybrid:false}
|
|
|
275 |
invalidMessage="Invalid IPv4 address.">
|
|
|
276 |
</div>
|
|
|
277 |
|
|
|
278 |
<div class="dojoTitlePaneLabel">
|
|
|
279 |
<label for="q10"> IPv6 Address: </label>
|
|
|
280 |
<span class="noticeMessage">IpAddressTextBox class,
|
|
|
281 |
Attributes: {allowDottedDecimal: false, allowDottedHex: false}.
|
|
|
282 |
Also hybrid works, x:x:x:x:x:x:d.d.d.d</span>
|
|
|
283 |
</div>
|
|
|
284 |
<div class="testExample">
|
|
|
285 |
<input id="q10" type="text" name="ipv6" class="long" value="0000:0000:0000:0000:0000:0000:0000:0000"
|
|
|
286 |
dojoType="dijit.form.ValidationTextBox"
|
|
|
287 |
regExpGen="dojo.regexp.ipAddress"
|
|
|
288 |
trim="true"
|
|
|
289 |
uppercase = "true"
|
|
|
290 |
required="true"
|
|
|
291 |
constraints={allowDottedDecimal:false, allowDottedHex:false, allowDottedOctal:false}
|
|
|
292 |
invalidMessage="Invalid IPv6 address, please enter eight groups of four hexadecimal digits. x:x:x:x:x:x:x:x">
|
|
|
293 |
</div>
|
|
|
294 |
|
|
|
295 |
<div class="dojoTitlePaneLabel">
|
|
|
296 |
<label for="q11"> URL: </label>
|
|
|
297 |
<span class="noticeMessage">UrlTextBox class,
|
|
|
298 |
Attributes: {required: true, trim: true, scheme: true}. </span>
|
|
|
299 |
</div>
|
|
|
300 |
|
|
|
301 |
<div class="testExample">
|
|
|
302 |
<input id="q11" type="text" name="url" class="long" value="http://www.xyz.com/a/b/c?x=2#p3"
|
|
|
303 |
dojoType="dijit.form.ValidationTextBox"
|
|
|
304 |
regExpGen="dojo.regexp.url"
|
|
|
305 |
trim="true"
|
|
|
306 |
required="true"
|
|
|
307 |
constraints={scheme:true}
|
|
|
308 |
invalidMessage="Invalid URL. Be sure to include the scheme, http://..." />
|
|
|
309 |
</div>
|
|
|
310 |
|
|
|
311 |
<div class="dojoTitlePaneLabel">
|
|
|
312 |
<label for="q12"> Email Address </label>
|
|
|
313 |
<span class="noticeMessage">EmailTextBox class,
|
|
|
314 |
Attributes: {required: true, trim: true}. </span>
|
|
|
315 |
</div>
|
|
|
316 |
|
|
|
317 |
<div class="testExample">
|
|
|
318 |
<input id="q12" type="text" name="email" class="long" value="fred&barney@stonehenge.com"
|
|
|
319 |
dojoType="dijit.form.ValidationTextBox"
|
|
|
320 |
regExpGen="dojo.regexp.emailAddress"
|
|
|
321 |
trim="true"
|
|
|
322 |
required="true"
|
|
|
323 |
invalidMessage="Invalid Email Address." />
|
|
|
324 |
</div>
|
|
|
325 |
|
|
|
326 |
<div class="dojoTitlePaneLabel">
|
|
|
327 |
<label for="q13"> Email Address List </label>
|
|
|
328 |
<span class="noticeMessage">EmailListTextBox class,
|
|
|
329 |
Attributes: {required: true, trim: true}. </span>
|
|
|
330 |
</div>
|
|
|
331 |
|
|
|
332 |
<div class="testExample">
|
|
|
333 |
<input id="q13" type="text" name="email" class="long" value="a@xyz.com; b@xyz.com; c@xyz.com; "
|
|
|
334 |
dojoType="dijit.form.ValidationTextBox"
|
|
|
335 |
regExpGen="dojo.regexp.emailAddressList"
|
|
|
336 |
trim="true"
|
|
|
337 |
required="true"
|
|
|
338 |
invalidMessage="Invalid Email Address List." />
|
|
|
339 |
</div>
|
|
|
340 |
-->
|
|
|
341 |
<div class="dojoTitlePaneLabel">
|
|
|
342 |
<label for="q22">Regular Expression </label>
|
|
|
343 |
<span class="noticeMessage">RegexpTextBox class,
|
|
|
344 |
Attributes: {required: true} </span>
|
|
|
345 |
</div>
|
|
|
346 |
<div class="testExample">
|
|
|
347 |
<input id="q22" type="text" name="phone" class="medium" value="someTestString"
|
|
|
348 |
dojoType="dijit.form.ValidationTextBox"
|
|
|
349 |
regExp="[\w]+"
|
|
|
350 |
required="true"
|
|
|
351 |
invalidMessage="Invalid Non-Space Text.">
|
|
|
352 |
</div>
|
|
|
353 |
|
|
|
354 |
<div class="dojoTitlePaneLabel">
|
|
|
355 |
<label for="q23"> Password </label>
|
|
|
356 |
<span class="noticeMessage">(just a test that type attribute is obeyed) </span>
|
|
|
357 |
</div>
|
|
|
358 |
<div class="testExample">
|
|
|
359 |
<input id="q23" type="password" name="password" class="medium"
|
|
|
360 |
dojoType="dijit.form.TextBox">
|
|
|
361 |
</div>
|
|
|
362 |
|
|
|
363 |
<div class="dojoTitlePaneLabel">
|
|
|
364 |
<label for="ticket1651">Trac ticket 1651: </label>
|
|
|
365 |
<span class="noticeMessage">value: null should show up as empty</span>
|
|
|
366 |
</div>
|
|
|
367 |
<div class="testExample">
|
|
|
368 |
<input id="ticket1651" class="medium" value="not null"/>
|
|
|
369 |
</div>
|
|
|
370 |
|
|
|
371 |
<script>
|
|
|
372 |
// See if we can make a widget in script and attach it to the DOM ourselves.
|
|
|
373 |
dojo.addOnLoad(function(){
|
|
|
374 |
var props = {
|
|
|
375 |
name: "ticket1651",
|
|
|
376 |
id: "mname",
|
|
|
377 |
value: null
|
|
|
378 |
};
|
|
|
379 |
var w = new dijit.form.TextBox(props, "ticket1651");
|
|
|
380 |
});
|
|
|
381 |
</script>
|
|
|
382 |
<script>
|
|
|
383 |
function displayData() {
|
|
|
384 |
var f = document.getElementById("form1");
|
|
|
385 |
var s = "";
|
|
|
386 |
for (var i = 0; i < f.elements.length; i++) {
|
|
|
387 |
var elem = f.elements[i];
|
|
|
388 |
if (elem.name == "button") { continue; }
|
|
|
389 |
s += elem.name + ": " + elem.value + "\n";
|
|
|
390 |
}
|
|
|
391 |
alert(s);
|
|
|
392 |
}
|
|
|
393 |
</script>
|
|
|
394 |
|
|
|
395 |
<div>
|
|
|
396 |
<button name="button" onclick="displayData(); return false;">view data</button>
|
|
|
397 |
<input type="submit" name="submit" />
|
|
|
398 |
</div>
|
|
|
399 |
|
|
|
400 |
</form>
|
|
|
401 |
</body>
|
|
|
402 |
</html>
|