1 |
5703
|
leinfelder
|
<!DOCTYPE html>
|
2 |
|
|
<html lang="en">
|
3 |
|
|
<head>
|
4 |
|
|
<meta charset="utf-8">
|
5 |
|
|
<title>jQuery UI Dialog - Modal form</title>
|
6 |
|
|
<link rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
|
7 |
|
|
<script src="../../jquery-1.4.3.js"></script>
|
8 |
|
|
<script src="../../external/jquery.bgiframe-2.1.2.js"></script>
|
9 |
|
|
<script src="../../ui/jquery.ui.core.js"></script>
|
10 |
|
|
<script src="../../ui/jquery.ui.widget.js"></script>
|
11 |
|
|
<script src="../../ui/jquery.ui.mouse.js"></script>
|
12 |
|
|
<script src="../../ui/jquery.ui.button.js"></script>
|
13 |
|
|
<script src="../../ui/jquery.ui.draggable.js"></script>
|
14 |
|
|
<script src="../../ui/jquery.ui.position.js"></script>
|
15 |
|
|
<script src="../../ui/jquery.ui.resizable.js"></script>
|
16 |
|
|
<script src="../../ui/jquery.ui.dialog.js"></script>
|
17 |
|
|
<script src="../../ui/jquery.effects.core.js"></script>
|
18 |
|
|
<link rel="stylesheet" href="../demos.css">
|
19 |
|
|
<style>
|
20 |
|
|
body { font-size: 62.5%; }
|
21 |
|
|
label, input { display:block; }
|
22 |
|
|
input.text { margin-bottom:12px; width:95%; padding: .4em; }
|
23 |
|
|
fieldset { padding:0; border:0; margin-top:25px; }
|
24 |
|
|
h1 { font-size: 1.2em; margin: .6em 0; }
|
25 |
|
|
div#users-contain { width: 350px; margin: 20px 0; }
|
26 |
|
|
div#users-contain table { margin: 1em 0; border-collapse: collapse; width: 100%; }
|
27 |
|
|
div#users-contain table td, div#users-contain table th { border: 1px solid #eee; padding: .6em 10px; text-align: left; }
|
28 |
|
|
.ui-dialog .ui-state-error { padding: .3em; }
|
29 |
|
|
.validateTips { border: 1px solid transparent; padding: 0.3em; }
|
30 |
|
|
</style>
|
31 |
|
|
<script>
|
32 |
|
|
$(function() {
|
33 |
|
|
// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
|
34 |
|
|
$( "#dialog:ui-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 |
|
|
if ( o.val().length > max || o.val().length < min ) {
|
53 |
|
|
o.addClass( "ui-state-error" );
|
54 |
|
|
updateTips( "Length of " + n + " must be between " +
|
55 |
|
|
min + " and " + max + "." );
|
56 |
|
|
return false;
|
57 |
|
|
} else {
|
58 |
|
|
return true;
|
59 |
|
|
}
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
function checkRegexp( o, regexp, n ) {
|
63 |
|
|
if ( !( regexp.test( o.val() ) ) ) {
|
64 |
|
|
o.addClass( "ui-state-error" );
|
65 |
|
|
updateTips( n );
|
66 |
|
|
return false;
|
67 |
|
|
} else {
|
68 |
|
|
return true;
|
69 |
|
|
}
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
$( "#dialog-form" ).dialog({
|
73 |
|
|
autoOpen: false,
|
74 |
|
|
height: 300,
|
75 |
|
|
width: 350,
|
76 |
|
|
modal: true,
|
77 |
|
|
buttons: {
|
78 |
|
|
"Create an account": function() {
|
79 |
|
|
var bValid = true;
|
80 |
|
|
allFields.removeClass( "ui-state-error" );
|
81 |
|
|
|
82 |
|
|
bValid = bValid && checkLength( name, "username", 3, 16 );
|
83 |
|
|
bValid = bValid && checkLength( email, "email", 6, 80 );
|
84 |
|
|
bValid = bValid && checkLength( password, "password", 5, 16 );
|
85 |
|
|
|
86 |
|
|
bValid = bValid && checkRegexp( name, /^[a-z]([0-9a-z_])+$/i, "Username may consist of a-z, 0-9, underscores, begin with a letter." );
|
87 |
|
|
// From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
|
88 |
|
|
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. ui@jquery.com" );
|
89 |
|
|
bValid = bValid && checkRegexp( password, /^([0-9a-zA-Z])+$/, "Password field only allow : a-z 0-9" );
|
90 |
|
|
|
91 |
|
|
if ( bValid ) {
|
92 |
|
|
$( "#users tbody" ).append( "<tr>" +
|
93 |
|
|
"<td>" + name.val() + "</td>" +
|
94 |
|
|
"<td>" + email.val() + "</td>" +
|
95 |
|
|
"<td>" + password.val() + "</td>" +
|
96 |
|
|
"</tr>" );
|
97 |
|
|
$( this ).dialog( "close" );
|
98 |
|
|
}
|
99 |
|
|
},
|
100 |
|
|
Cancel: function() {
|
101 |
|
|
$( this ).dialog( "close" );
|
102 |
|
|
}
|
103 |
|
|
},
|
104 |
|
|
close: function() {
|
105 |
|
|
allFields.val( "" ).removeClass( "ui-state-error" );
|
106 |
|
|
}
|
107 |
|
|
});
|
108 |
|
|
|
109 |
|
|
$( "#create-user" )
|
110 |
|
|
.button()
|
111 |
|
|
.click(function() {
|
112 |
|
|
$( "#dialog-form" ).dialog( "open" );
|
113 |
|
|
});
|
114 |
|
|
});
|
115 |
|
|
</script>
|
116 |
|
|
</head>
|
117 |
|
|
<body>
|
118 |
|
|
|
119 |
|
|
<div class="demo">
|
120 |
|
|
|
121 |
|
|
<div id="dialog-form" title="Create new user">
|
122 |
|
|
<p class="validateTips">All form fields are required.</p>
|
123 |
|
|
|
124 |
|
|
<form>
|
125 |
|
|
<fieldset>
|
126 |
|
|
<label for="name">Name</label>
|
127 |
|
|
<input type="text" name="name" id="name" class="text ui-widget-content ui-corner-all" />
|
128 |
|
|
<label for="email">Email</label>
|
129 |
|
|
<input type="text" name="email" id="email" value="" class="text ui-widget-content ui-corner-all" />
|
130 |
|
|
<label for="password">Password</label>
|
131 |
|
|
<input type="password" name="password" id="password" value="" class="text ui-widget-content ui-corner-all" />
|
132 |
|
|
</fieldset>
|
133 |
|
|
</form>
|
134 |
|
|
</div>
|
135 |
|
|
|
136 |
|
|
|
137 |
|
|
<div id="users-contain" class="ui-widget">
|
138 |
|
|
<h1>Existing Users:</h1>
|
139 |
|
|
<table id="users" class="ui-widget ui-widget-content">
|
140 |
|
|
<thead>
|
141 |
|
|
<tr class="ui-widget-header ">
|
142 |
|
|
<th>Name</th>
|
143 |
|
|
<th>Email</th>
|
144 |
|
|
<th>Password</th>
|
145 |
|
|
</tr>
|
146 |
|
|
</thead>
|
147 |
|
|
<tbody>
|
148 |
|
|
<tr>
|
149 |
|
|
<td>John Doe</td>
|
150 |
|
|
<td>john.doe@example.com</td>
|
151 |
|
|
<td>johndoe1</td>
|
152 |
|
|
</tr>
|
153 |
|
|
</tbody>
|
154 |
|
|
</table>
|
155 |
|
|
</div>
|
156 |
|
|
<button id="create-user">Create new user</button>
|
157 |
|
|
|
158 |
|
|
</div><!-- End demo -->
|
159 |
|
|
|
160 |
|
|
|
161 |
|
|
|
162 |
|
|
<div class="demo-description">
|
163 |
|
|
<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>
|
164 |
|
|
</div><!-- End demo-description -->
|
165 |
|
|
|
166 |
|
|
</body>
|
167 |
|
|
</html>
|