source: main/trunk/greenstone3/web/interfaces/oran/js/jquery-ui-1.8rc1/demos/dialog/modal-form.html@ 24245

Last change on this file since 24245 was 24245, checked in by sjb48, 13 years ago

Oran code for supporting format changes to document.

  • Property svn:executable set to *
File size: 6.4 KB
Line 
1<!doctype html>
2<html lang="en">
3<head>
4 <title>jQuery UI Dialog - Modal form</title>
5 <link type="text/css" href="../../themes/base/ui.all.css" rel="stylesheet" />
6 <script type="text/javascript" src="../../jquery-1.4.1.js"></script>
7 <script type="text/javascript" src="../../external/jquery.bgiframe-2.1.1.js"></script>
8 <script type="text/javascript" src="../../ui/jquery.ui.core.js"></script>
9 <script type="text/javascript" src="../../ui/jquery.ui.widget.js"></script>
10 <script type="text/javascript" src="../../ui/jquery.ui.mouse.js"></script>
11 <script type="text/javascript" src="../../ui/jquery.ui.button.js"></script>
12 <script type="text/javascript" src="../../ui/jquery.ui.draggable.js"></script>
13 <script type="text/javascript" src="../../ui/jquery.ui.position.js"></script>
14 <script type="text/javascript" src="../../ui/jquery.ui.resizable.js"></script>
15 <script type="text/javascript" src="../../ui/jquery.ui.dialog.js"></script>
16 <script type="text/javascript" src="../../ui/jquery.effects.core.js"></script>
17 <link type="text/css" href="../demos.css" rel="stylesheet" />
18 <style type="text/css">
19 body { font-size: 62.5%; }
20 label, input { display:block; }
21 input.text { margin-bottom:12px; width:95%; padding: .4em; }
22 fieldset { padding:0; border:0; margin-top:25px; }
23 h1 { font-size: 1.2em; margin: .6em 0; }
24 div#users-contain { width: 350px; margin: 20px 0; }
25 div#users-contain table { margin: 1em 0; border-collapse: collapse; width: 100%; }
26 div#users-contain table td, div#users-contain table th { border: 1px solid #eee; padding: .6em 10px; text-align: left; }
27 .ui-dialog .ui-state-error { padding: .3em; }
28 .validateTips { border: 1px solid transparent; padding: 0.3em; }
29
30 </style>
31 <script type="text/javascript">
32 $(function() {
33 // a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
34 $("#dialog").dialog("destroy");
35
36 var name = $("#name"),
37 email = $("#email"),
38 password = $("#password"),
39 allFields = $([]).add(name).add(email).add(password),
40 tips = $(".validateTips");
41
42 function updateTips(t) {
43 tips
44 .text(t)
45 .addClass('ui-state-highlight');
46 setTimeout(function() {
47 tips.removeClass('ui-state-highlight', 1500);
48 }, 500);
49 }
50
51 function checkLength(o,n,min,max) {
52
53 if ( o.val().length > max || o.val().length < min ) {
54 o.addClass('ui-state-error');
55 updateTips("Length of " + n + " must be between "+min+" and "+max+".");
56 return false;
57 } else {
58 return true;
59 }
60
61 }
62
63 function checkRegexp(o,regexp,n) {
64
65 if ( !( regexp.test( o.val() ) ) ) {
66 o.addClass('ui-state-error');
67 updateTips(n);
68 return false;
69 } else {
70 return true;
71 }
72
73 }
74
75 $("#dialog-form").dialog({
76 autoOpen: false,
77 height: 300,
78 width: 350,
79 modal: true,
80 buttons: {
81 'Create an account': function() {
82 var bValid = true;
83 allFields.removeClass('ui-state-error');
84
85 bValid = bValid && checkLength(name,"username",3,16);
86 bValid = bValid && checkLength(email,"email",6,80);
87 bValid = bValid && checkLength(password,"password",5,16);
88
89 bValid = bValid && checkRegexp(name,/^[a-z]([0-9a-z_])+$/i,"Username may consist of a-z, 0-9, underscores, begin with a letter.");
90 // From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
91 bValid = bValid && checkRegexp(email,/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,"eg. [email protected]");
92 bValid = bValid && checkRegexp(password,/^([0-9a-zA-Z])+$/,"Password field only allow : a-z 0-9");
93
94 if (bValid) {
95 $('#users tbody').append('<tr>' +
96 '<td>' + name.val() + '</td>' +
97 '<td>' + email.val() + '</td>' +
98 '<td>' + password.val() + '</td>' +
99 '</tr>');
100 $(this).dialog('close');
101 }
102 },
103 Cancel: function() {
104 $(this).dialog('close');
105 }
106 },
107 close: function() {
108 allFields.val('').removeClass('ui-state-error');
109 }
110 });
111
112
113
114 $('#create-user')
115 .button()
116 .click(function() {
117 $('#dialog-form').dialog('open');
118 });
119
120 });
121 </script>
122</head>
123<body>
124
125<div class="demo">
126
127<div id="dialog-form" title="Create new user">
128 <p class="validateTips">All form fields are required.</p>
129
130 <form>
131 <fieldset>
132 <label for="name">Name</label>
133 <input type="text" name="name" id="name" class="text ui-widget-content ui-corner-all" />
134 <label for="email">Email</label>
135 <input type="text" name="email" id="email" value="" class="text ui-widget-content ui-corner-all" />
136 <label for="password">Password</label>
137 <input type="password" name="password" id="password" value="" class="text ui-widget-content ui-corner-all" />
138 </fieldset>
139 </form>
140</div>
141
142
143<div id="users-contain" class="ui-widget">
144
145 <h1>Existing Users:</h1>
146
147
148 <table id="users" class="ui-widget ui-widget-content">
149 <thead>
150 <tr class="ui-widget-header ">
151 <th>Name</th>
152 <th>Email</th>
153 <th>Password</th>
154 </tr>
155 </thead>
156 <tbody>
157 <tr>
158 <td>John Doe</td>
159 <td>[email protected]</td>
160 <td>johndoe1</td>
161 </tr>
162 </tbody>
163 </table>
164</div>
165<button id="create-user">Create new user</button>
166
167</div><!-- End demo -->
168
169<div class="demo-description">
170
171<p>Use a modal dialog to require that the user enter data during a multi-step process. Embed form markup in the content area, set the <code>modal</code> option to true, and specify primary and secondary user actions with the <code>buttons</code> option.</p>
172
173</div><!-- End demo-description -->
174
175</body>
176</html>
Note: See TracBrowser for help on using the repository browser.