| 2 |
lars |
1 |
<!DOCTYPE html>
|
|
|
2 |
<html lang="en">
|
|
|
3 |
<head>
|
|
|
4 |
<meta charset="utf-8">
|
|
|
5 |
<title>jQuery validation plug-in - main demo</title>
|
|
|
6 |
<link rel="stylesheet" href="css/screen.css">
|
|
|
7 |
<script src="../lib/jquery.js"></script>
|
|
|
8 |
<script src="../dist/jquery.validate.js"></script>
|
|
|
9 |
<script>
|
|
|
10 |
$.validator.setDefaults({
|
|
|
11 |
submitHandler: function() {
|
|
|
12 |
alert("submitted!");
|
|
|
13 |
}
|
|
|
14 |
});
|
|
|
15 |
|
|
|
16 |
$().ready(function() {
|
|
|
17 |
// validate the comment form when it is submitted
|
|
|
18 |
$("#commentForm").validate();
|
|
|
19 |
|
|
|
20 |
// validate signup form on keyup and submit
|
|
|
21 |
$("#signupForm").validate({
|
|
|
22 |
rules: {
|
|
|
23 |
firstname: "required",
|
|
|
24 |
lastname: "required",
|
|
|
25 |
username: {
|
|
|
26 |
required: true,
|
|
|
27 |
minlength: 2
|
|
|
28 |
},
|
|
|
29 |
password: {
|
|
|
30 |
required: true,
|
|
|
31 |
minlength: 5
|
|
|
32 |
},
|
|
|
33 |
confirm_password: {
|
|
|
34 |
required: true,
|
|
|
35 |
minlength: 5,
|
|
|
36 |
equalTo: "#password"
|
|
|
37 |
},
|
|
|
38 |
email: {
|
|
|
39 |
required: true,
|
|
|
40 |
email: true
|
|
|
41 |
},
|
|
|
42 |
topic: {
|
|
|
43 |
required: "#newsletter:checked",
|
|
|
44 |
minlength: 2
|
|
|
45 |
},
|
|
|
46 |
agree: "required"
|
|
|
47 |
},
|
|
|
48 |
messages: {
|
|
|
49 |
firstname: "Please enter your firstname",
|
|
|
50 |
lastname: "Please enter your lastname",
|
|
|
51 |
username: {
|
|
|
52 |
required: "Please enter a username",
|
|
|
53 |
minlength: "Your username must consist of at least 2 characters"
|
|
|
54 |
},
|
|
|
55 |
password: {
|
|
|
56 |
required: "Please provide a password",
|
|
|
57 |
minlength: "Your password must be at least 5 characters long"
|
|
|
58 |
},
|
|
|
59 |
confirm_password: {
|
|
|
60 |
required: "Please provide a password",
|
|
|
61 |
minlength: "Your password must be at least 5 characters long",
|
|
|
62 |
equalTo: "Please enter the same password as above"
|
|
|
63 |
},
|
|
|
64 |
email: "Please enter a valid email address",
|
|
|
65 |
agree: "Please accept our policy",
|
|
|
66 |
topic: "Please select at least 2 topics"
|
|
|
67 |
}
|
|
|
68 |
});
|
|
|
69 |
|
|
|
70 |
// propose username by combining first- and lastname
|
|
|
71 |
$("#username").focus(function() {
|
|
|
72 |
var firstname = $("#firstname").val();
|
|
|
73 |
var lastname = $("#lastname").val();
|
|
|
74 |
if (firstname && lastname && !this.value) {
|
|
|
75 |
this.value = firstname + "." + lastname;
|
|
|
76 |
}
|
|
|
77 |
});
|
|
|
78 |
|
|
|
79 |
//code to hide topic selection, disable for demo
|
|
|
80 |
var newsletter = $("#newsletter");
|
|
|
81 |
// newsletter topics are optional, hide at first
|
|
|
82 |
var inital = newsletter.is(":checked");
|
|
|
83 |
var topics = $("#newsletter_topics")[inital ? "removeClass" : "addClass"]("gray");
|
|
|
84 |
var topicInputs = topics.find("input").attr("disabled", !inital);
|
|
|
85 |
// show when newsletter is checked
|
|
|
86 |
newsletter.click(function() {
|
|
|
87 |
topics[this.checked ? "removeClass" : "addClass"]("gray");
|
|
|
88 |
topicInputs.attr("disabled", !this.checked);
|
|
|
89 |
});
|
|
|
90 |
});
|
|
|
91 |
</script>
|
|
|
92 |
<style>
|
|
|
93 |
#commentForm {
|
|
|
94 |
width: 500px;
|
|
|
95 |
}
|
|
|
96 |
#commentForm label {
|
|
|
97 |
width: 250px;
|
|
|
98 |
}
|
|
|
99 |
#commentForm label.error, #commentForm input.submit {
|
|
|
100 |
margin-left: 253px;
|
|
|
101 |
}
|
|
|
102 |
#signupForm {
|
|
|
103 |
width: 670px;
|
|
|
104 |
}
|
|
|
105 |
#signupForm label.error {
|
|
|
106 |
margin-left: 10px;
|
|
|
107 |
width: auto;
|
|
|
108 |
display: inline;
|
|
|
109 |
}
|
|
|
110 |
#newsletter_topics label.error {
|
|
|
111 |
display: none;
|
|
|
112 |
margin-left: 103px;
|
|
|
113 |
}
|
|
|
114 |
</style>
|
|
|
115 |
</head>
|
|
|
116 |
<body>
|
|
|
117 |
<h1 id="banner"><a href="https://jqueryvalidation.org/">jQuery Validation Plugin</a> Demo</h1>
|
|
|
118 |
<div id="main">
|
|
|
119 |
<p>Default submitHandler is set to display an alert into of submitting the form</p>
|
|
|
120 |
<form class="cmxform" id="commentForm" method="get" action="">
|
|
|
121 |
<fieldset>
|
|
|
122 |
<legend>Please provide your name, email address (won't be published) and a comment</legend>
|
|
|
123 |
<p>
|
|
|
124 |
<label for="cname">Name (required, at least 2 characters)</label>
|
|
|
125 |
<input id="cname" name="name" minlength="2" type="text" required>
|
|
|
126 |
</p>
|
|
|
127 |
<p>
|
|
|
128 |
<label for="cemail">E-Mail (required)</label>
|
|
|
129 |
<input id="cemail" type="email" name="email" required>
|
|
|
130 |
</p>
|
|
|
131 |
<p>
|
|
|
132 |
<label for="curl">URL (optional)</label>
|
|
|
133 |
<input id="curl" type="url" name="url">
|
|
|
134 |
</p>
|
|
|
135 |
<p>
|
|
|
136 |
<label for="ccomment">Your comment (required)</label>
|
|
|
137 |
<textarea id="ccomment" name="comment" required></textarea>
|
|
|
138 |
</p>
|
|
|
139 |
<p>
|
|
|
140 |
<input class="submit" type="submit" value="Submit">
|
|
|
141 |
</p>
|
|
|
142 |
</fieldset>
|
|
|
143 |
</form>
|
|
|
144 |
<form class="cmxform" id="signupForm" method="get" action="">
|
|
|
145 |
<fieldset>
|
|
|
146 |
<legend>Validating a complete form</legend>
|
|
|
147 |
<p>
|
|
|
148 |
<label for="firstname">Firstname</label>
|
|
|
149 |
<input id="firstname" name="firstname" type="text">
|
|
|
150 |
</p>
|
|
|
151 |
<p>
|
|
|
152 |
<label for="lastname">Lastname</label>
|
|
|
153 |
<input id="lastname" name="lastname" type="text">
|
|
|
154 |
</p>
|
|
|
155 |
<p>
|
|
|
156 |
<label for="username">Username</label>
|
|
|
157 |
<input id="username" name="username" type="text">
|
|
|
158 |
</p>
|
|
|
159 |
<p>
|
|
|
160 |
<label for="password">Password</label>
|
|
|
161 |
<input id="password" name="password" type="password">
|
|
|
162 |
</p>
|
|
|
163 |
<p>
|
|
|
164 |
<label for="confirm_password">Confirm password</label>
|
|
|
165 |
<input id="confirm_password" name="confirm_password" type="password">
|
|
|
166 |
</p>
|
|
|
167 |
<p>
|
|
|
168 |
<label for="email">Email</label>
|
|
|
169 |
<input id="email" name="email" type="email">
|
|
|
170 |
</p>
|
|
|
171 |
<p>
|
|
|
172 |
<label for="agree">Please agree to our policy</label>
|
|
|
173 |
<input type="checkbox" class="checkbox" id="agree" name="agree">
|
|
|
174 |
</p>
|
|
|
175 |
<p>
|
|
|
176 |
<label for="newsletter">I'd like to receive the newsletter</label>
|
|
|
177 |
<input type="checkbox" class="checkbox" id="newsletter" name="newsletter">
|
|
|
178 |
</p>
|
|
|
179 |
<fieldset id="newsletter_topics">
|
|
|
180 |
<legend>Topics (select at least two) - note: would be hidden when newsletter isn't selected, but is visible here for the demo</legend>
|
|
|
181 |
<label for="topic_marketflash">
|
|
|
182 |
<input type="checkbox" id="topic_marketflash" value="marketflash" name="topic">Marketflash
|
|
|
183 |
</label>
|
|
|
184 |
<label for="topic_fuzz">
|
|
|
185 |
<input type="checkbox" id="topic_fuzz" value="fuzz" name="topic">Latest fuzz
|
|
|
186 |
</label>
|
|
|
187 |
<label for="topic_digester">
|
|
|
188 |
<input type="checkbox" id="topic_digester" value="digester" name="topic">Mailing list digester
|
|
|
189 |
</label>
|
|
|
190 |
<label for="topic" class="error">Please select at least two topics you'd like to receive.</label>
|
|
|
191 |
</fieldset>
|
|
|
192 |
<p>
|
|
|
193 |
<input class="submit" type="submit" value="Submit">
|
|
|
194 |
</p>
|
|
|
195 |
</fieldset>
|
|
|
196 |
</form>
|
|
|
197 |
<h3>Synthetic examples</h3>
|
|
|
198 |
<ul>
|
|
|
199 |
<li><a href="errorcontainer-demo.html">Error message containers in action</a>
|
|
|
200 |
</li>
|
|
|
201 |
<li><a href="custom-messages-data-demo.html">Custom Messages as Element Data</a>
|
|
|
202 |
</li>
|
|
|
203 |
<li><a href="radio-checkbox-select-demo.html">Radio and checkbox buttons and selects</a>
|
|
|
204 |
</li>
|
|
|
205 |
<li><a href="ajaxSubmit-integration-demo.html">Integration with Form Plugin (AJAX submit)</a>
|
|
|
206 |
</li>
|
|
|
207 |
<li><a href="custom-methods-demo.html">Custom methods and message display.</a>
|
|
|
208 |
</li>
|
|
|
209 |
<li><a href="dynamic-totals.html">Dynamic forms</a>
|
|
|
210 |
</li>
|
|
|
211 |
<li><a href="themerollered.html">Forms styled with jQuery UI Themeroller</a>
|
|
|
212 |
</li>
|
|
|
213 |
<li><a href="tinymce/">TinyMCE3 Demo</a>
|
|
|
214 |
</li>
|
|
|
215 |
<li><a href="tinymce4/">TinyMCE4 Demo</a>
|
|
|
216 |
</li>
|
|
|
217 |
<li><a href="file_input.html">File inputs</a>
|
|
|
218 |
</li>
|
|
|
219 |
<li><a href="jquerymobile.html">jQuery Mobile Form Validation</a>
|
|
|
220 |
</li>
|
|
|
221 |
<li><a href="errors-within-labels.html">Displaying Errors within Field Labels</a>
|
|
|
222 |
</li>
|
|
|
223 |
<li><a href="requirejs/index.html">Loading via RequireJS</a>
|
|
|
224 |
</li>
|
|
|
225 |
<li><a href="bootstrap/index.html">Using with Bootstrap</a>
|
|
|
226 |
</li>
|
|
|
227 |
<li><a href="semantic-ui/index.html">Using with Semantic-UI</a>
|
|
|
228 |
</li>
|
|
|
229 |
</ul>
|
|
|
230 |
<h3>Real-world examples</h3>
|
|
|
231 |
<ul>
|
|
|
232 |
<li><a href="cinema/">Retro Cinema Registration</a></li>
|
|
|
233 |
<li><a href="milk/">Remember The Milk signup form</a></li>
|
|
|
234 |
<li><a href="marketo/">Marketo signup form</a></li>
|
|
|
235 |
<li><a href="multipart/">Buy and Sell a House multipart form</a></li>
|
|
|
236 |
<li><a href="captcha/">Remote captcha validation</a></li>
|
|
|
237 |
</ul>
|
|
|
238 |
</div>
|
|
|
239 |
</body>
|
|
|
240 |
</html>
|