5 <title>jQuery UI Dialog - Modal form</title>
6 <link rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
7 <script src="../../jquery-1.9.1.js"></script>
8 <script src="../../ui/jquery.ui.core.js"></script>
9 <script src="../../ui/jquery.ui.widget.js"></script>
10 <script src="../../ui/jquery.ui.mouse.js"></script>
11 <script src="../../ui/jquery.ui.button.js"></script>
12 <script src="../../ui/jquery.ui.draggable.js"></script>
13 <script src="../../ui/jquery.ui.position.js"></script>
14 <script src="../../ui/jquery.ui.resizable.js"></script>
15 <script src="../../ui/jquery.ui.button.js"></script>
16 <script src="../../ui/jquery.ui.dialog.js"></script>
17 <script src="../../ui/jquery.ui.effect.js"></script>
18 <link rel="stylesheet" href="../demos.css">
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; }
33 var name = $( "#name" ),
34 email = $( "#email" ),
35 password = $( "#password" ),
36 allFields = $( [] ).add( name ).add( email ).add( password ),
37 tips = $( ".validateTips" );
39 function updateTips( t ) {
42 .addClass( "ui-state-highlight" );
43 setTimeout(function() {
44 tips.removeClass( "ui-state-highlight", 1500 );
48 function checkLength( o, n, min, max ) {
49 if ( o.val().length > max || o.val().length < min ) {
50 o.addClass( "ui-state-error" );
51 updateTips( "Length of " + n + " must be between " +
52 min + " and " + max + "." );
59 function checkRegexp( o, regexp, n ) {
60 if ( !( regexp.test( o.val() ) ) ) {
61 o.addClass( "ui-state-error" );
69 $( "#dialog-form" ).dialog({
75 "Create an account": function() {
77 allFields.removeClass( "ui-state-error" );
79 bValid = bValid && checkLength( name, "username", 3, 16 );
80 bValid = bValid && checkLength( email, "email", 6, 80 );
81 bValid = bValid && checkLength( password, "password", 5, 16 );
83 bValid = bValid && checkRegexp( name, /^[a-z]([0-9a-z_])+$/i, "Username may consist of a-z, 0-9, underscores, begin with a letter." );
84 // From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
85 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]" );
86 bValid = bValid && checkRegexp( password, /^([0-9a-zA-Z])+$/, "Password field only allow : a-z 0-9" );
89 $( "#users tbody" ).append( "<tr>" +
90 "<td>" + name.val() + "</td>" +
91 "<td>" + email.val() + "</td>" +
92 "<td>" + password.val() + "</td>" +
94 $( this ).dialog( "close" );
98 $( this ).dialog( "close" );
102 allFields.val( "" ).removeClass( "ui-state-error" );
109 $( "#dialog-form" ).dialog( "open" );
116 <div id="dialog-form" title="Create new user">
117 <p class="validateTips">All form fields are required.</p>
121 <label for="name">Name</label>
122 <input type="text" name="name" id="name" class="text ui-widget-content ui-corner-all" />
123 <label for="email">Email</label>
124 <input type="text" name="email" id="email" value="" class="text ui-widget-content ui-corner-all" />
125 <label for="password">Password</label>
126 <input type="password" name="password" id="password" value="" class="text ui-widget-content ui-corner-all" />
132 <div id="users-contain" class="ui-widget">
133 <h1>Existing Users:</h1>
134 <table id="users" class="ui-widget ui-widget-content">
136 <tr class="ui-widget-header ">
151 <button id="create-user">Create new user</button>
153 <div class="demo-description">
154 <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>