7
7
8
8
< script type ="text/javascript " src ="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js "> </ script >
9
9
< script type ="text/javascript " src ="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.min.js "> </ script >
10
+ < script type ="text/javascript " src ="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js "> </ script >
10
11
11
12
< script type ="text/javascript " src ="../js/jquery.dform.js "> </ script >
12
13
< script type ="text/javascript " src ="../js/jquery.dform.subscriptions.js "> </ script >
27
28
var data = $ . parseJSON ( $ ( dataselector ) . html ( ) ) ;
28
29
$ ( this ) . buildForm ( data ) ;
29
30
} ) ;
30
-
31
+
31
32
SyntaxHighlighter . all ( ) ;
32
33
$ ( ".tabs" ) . tabs ( ) ; // Make jQuery UI tabs on this page
33
34
eval ( $ ( "#firstsample" ) . html ( ) ) ;
@@ -97,8 +98,8 @@ <h2>What it is for</h2>
97
98
< a name ="examples "> </ a >
98
99
< h2 > Examples</ h2 >
99
100
< h3 > Login form</ h3 >
100
- < p > A simple login form. The hint in the username textfield will dissapear when
101
- you focus it.</ p >
101
+ < p > A simple login form. The hint in the username field will dissapear when
102
+ you focus it or submit the form .</ p >
102
103
103
104
< div class ="exampleform tabs ">
104
105
< ul >
@@ -142,11 +143,14 @@ <h3>Login form</h3>
142
143
</ div >
143
144
144
145
< h3 > Registration form</ h3 >
145
- < p > A more complex form</ p >
146
+ < p > A more complex form with form field validation using the well established
147
+ jQuery validation plugin (submit to see validation messages)</ p >
146
148
147
149
< style type ="text/css ">
148
- # registrationform fieldset { width : 45% ; float : left; height : 400 px ; margin-right : 5px ; }
150
+ # registrationform fieldset { width : 45% ; float : left; height : 420 px ; margin-right : 5px ; }
149
151
# registrationform input [type = submit ] { margin : 10px 0 ; }
152
+ # registrationform label .error { font-size : 80% ; color : # e14f1c ; margin-left : 10px ; }
153
+ # registrationform input .error { border : 1px solid # e14f1c ; }
150
154
</ style >
151
155
< div class ="exampleform tabs ">
152
156
< ul >
@@ -171,18 +175,41 @@ <h3>Registration form</h3>
171
175
"name" : "email",
172
176
"label" : "Email address",
173
177
"type" : "text",
174
- "hint" : "E.g. user@example.com"
178
+ "hint" : "E.g. user@example.com",
179
+ "validate" :
180
+ {
181
+ "email" : true
182
+ }
175
183
},
176
184
{
177
185
"name" : "password",
178
186
"label" : "Password",
179
- "type" : "password"
187
+ "type" : "password",
188
+ "id" : "registration-password",
189
+ "validate" :
190
+ {
191
+ "required" : true,
192
+ "minlength" : 5,
193
+ "messages" :
194
+ {
195
+ "required" : "Please enter a password",
196
+ "minlength" : "At least {0} characters long"
197
+ }
198
+ }
180
199
},
181
200
{
182
201
"name" : "password-repeat",
183
202
"label" : "Repeat password",
184
- "type" : "password"
185
- },
203
+ "type" : "password",
204
+ "validate" :
205
+ {
206
+ "equalTo" : "#registration-password",
207
+ "messages" :
208
+ {
209
+ "equalTo" : "Please repeat your password"
210
+ }
211
+ }
212
+ }
186
213
]
187
214
},
188
215
{
@@ -198,29 +225,37 @@ <h3>Registration form</h3>
198
225
{
199
226
"name" : "address",
200
227
"label" : "Address",
201
- "type" : "text"
228
+ "type" : "text",
229
+ "validate" : { "required" : true }
202
230
},
203
231
{
204
232
"name" : "zip",
205
233
"label" : "ZIP code",
206
234
"type" : "text",
207
- "size" : 5
235
+ "size" : 5,
236
+ "validate" : { "required" : true }
208
237
},
209
238
{
210
239
"name" : "city",
211
240
"label" : "City",
212
- "type" : "text"
241
+ "type" : "text",
242
+ "validate" : { "required" : true }
213
243
},
214
244
{
215
245
"type" : "select",
216
- "name" : "country ",
217
- "label" : "Choose country ",
246
+ "name" : "continent ",
247
+ "label" : "Choose a continent ",
218
248
"options" :
219
249
{
220
- "can" : "Canada",
221
- "ger" : "Germany",
222
- "us" : "USA",
223
- "fr" : "France"
250
+ "america" : "America",
251
+ "europe" :
252
+ {
253
+ "selected" : "true",
254
+ "id" : "europe-option",
255
+ "value" : "Europe"
256
+ },
257
+ "asia" : "Asia",
258
+ "australia" : "Australia"
224
259
}
225
260
}
226
261
]
@@ -236,28 +271,117 @@ <h3>Registration form</h3>
236
271
</ div >
237
272
238
273
< style type ="text/css ">
239
- # uiform .ui-tabs { position : absolute; left : 400px ; top : 70px ; }
240
- # uiform .ui-tabs div .ui-widget-content { width : 300px ; height : 70px ; }
274
+ # uiform label .error { font-size : 80% ; color : # e14f1c ; margin-left : 10px ; }
241
275
</ style >
276
+ < script type ="text/javascript "> <!--
277
+ $ ( document ) . ready ( function ( ) {
278
+ $ ( "#dialogbutton" ) . click ( function ( ) {
279
+ $ ( "#uiform" ) . dialog ( "open" ) ;
280
+ } ) ;
281
+ } ) ;
282
+ --></ script >
242
283
< h3 > jQuery UI</ h3 >
243
284
< p > The plugin comes with support for the great jQuery UI framework and its controls.
244
- If the form has the ui-widget class jQuery UI button and input styles
245
- will be applied to any matching type.</ p >
285
+ If the form has the < strong > .ui-widget</ strong > class matching jQuery UI styles will be applied
286
+ to all buttons and input elements as well as the validation messages.</ p >
287
+ < p > Example for standard form enhanced with jQuery UI css, showing in a jQuery UI modal dialog</ p >
246
288
< div class ="exampleform tabs ">
247
289
< ul >
248
290
< li > < a href ="#uiform-div "> Form</ a > </ li >
249
291
< li > < a href ="#uiform-src "> JSON</ a > </ li >
250
292
</ ul >
251
293
< div id ="uiform-div ">
294
+ < button id ="dialogbutton "> Show form</ button >
252
295
< form id ="uiform " class ="dform ui-widget "> </ form >
253
296
</ div >
254
297
< div id ="uiform-src ">
298
+ < pre class ="brush: js ">
299
+ {
300
+ "action" : "index.html",
301
+ "method" : "get",
302
+ "title" : "A dialog form",
303
+ "dialog" :
304
+ {
305
+ "modal" : true,
306
+ "autoOpen" : false
307
+ },
308
+ "elements" : [
309
+ {
310
+ "name" : "email",
311
+ "label" : "Email address",
312
+ "type" : "text",
313
+ "validate" :
314
+ {
315
+ "required" : true,
316
+ "email" : true
317
+ }
318
+ },
319
+ {
320
+ "name" : "password",
321
+ "label" : "Password",
322
+ "type" : "password",
323
+ "id" : "dialog-registration-password",
324
+ "validate" :
325
+ {
326
+ "required" : true,
327
+ "minlength" : 5,
328
+ "messages" :
329
+ {
330
+ "required" : "Please enter a password",
331
+ "minlength" : "At least {0} characters long"
332
+ }
333
+ }
334
+ },
335
+ {
336
+ "name" : "password-repeat",
337
+ "label" : "Repeat password",
338
+ "type" : "password",
339
+ "validate" :
340
+ {
341
+ "equalTo" : "#dialog-registration-password",
342
+ "messages" :
343
+ {
344
+ "equalTo" : "Please repeat your password"
345
+ }
346
+ }
347
+ },
348
+ {
349
+ "type" : "submit",
350
+ "value" : "Signup"
351
+ }
352
+ ]
353
+ }
354
+ </ pre >
355
+ </ div >
356
+ </ div >
357
+
358
+ < p > Examples for supported jQuery UI widgets</ p >
359
+ < style type ="text/css ">
360
+ # uiwidgets .ui-tabs { position : absolute; left : 400px ; top : 70px ; }
361
+ # uiwidgets .ui-tabs div .ui-widget-content { width : 300px ; height : 70px ; }
362
+ </ style >
363
+ < div class ="exampleform tabs ">
364
+ < ul >
365
+ < li > < a href ="#uiwidgets-div "> Form</ a > </ li >
366
+ < li > < a href ="#uiwidgets-src "> JSON</ a > </ li >
367
+ </ ul >
368
+ < div id ="uiwidgets-div ">
369
+ < form id ="uiwidgets " class ="dform ui-widget "> </ form >
370
+ </ div >
371
+ < div id ="uiwidgets-src ">
255
372
< pre class ="brush: js ">
256
373
{
257
374
"action" : "index.html",
258
375
"method" : "get",
259
376
"elements" :
260
377
[
378
+ {
379
+ "type" : "slider",
380
+ "values" : [ 10, 80 ],
381
+ "range" : true,
382
+ "label" : "Slider",
383
+ "id" : "myslider"
384
+ },
261
385
{
262
386
"name" : "textfield",
263
387
"label" : "Autocomplete",
@@ -268,25 +392,14 @@ <h3>jQuery UI</h3>
268
392
"source" : [ "Apple", "Acer", "Sony", "Summer" ]
269
393
}
270
394
},
271
- {
272
- "label" : "A themed submit button",
273
- "type" : "submit",
274
- "value" : "Login"
275
- },
276
395
{
277
396
"name" : "date",
278
397
"label" : "Datepicker",
279
398
"type" : "text",
280
399
"datepicker" : { "showOn" : "button" }
281
400
},
282
401
{
283
- "type" : "slider",
284
- "values" : [ 10, 80 ],
285
- "range" : true,
286
- "label" : "Slider"
287
- },
288
- {
289
- "label" : "Some progress",
402
+ "label" : "A progressbar",
290
403
"type" : "progressbar",
291
404
"value" : 40
292
405
},
@@ -306,7 +419,7 @@ <h3>jQuery UI</h3>
306
419
[
307
420
{
308
421
"name" : "textfield",
309
- "label" : "Just a textfield in jQuery UI tabs ",
422
+ "label" : "Just a textfield",
310
423
"type" : "text"
311
424
}
312
425
]
@@ -333,7 +446,7 @@ <h3>jQuery UI</h3>
333
446
</ pre >
334
447
</ div >
335
448
</ div >
336
-
449
+
337
450
< a name ="about "> </ a >
338
451
< h2 > About</ h2 >
339
452
< p > Download the < a target ="_blank " href ="http://github.com/daffl/jquery.dform/downloads "> jQuery.dForm package</ a > </ p >
0 commit comments