| 2 |
lars |
1 |
<!DOCTYPE html>
|
|
|
2 |
<html lang="en">
|
|
|
3 |
<head>
|
|
|
4 |
<meta charset="utf-8">
|
|
|
5 |
<title>Test for jQuery validate() plugin</title>
|
|
|
6 |
<link rel="stylesheet" media="screen" href="css/screen.css">
|
|
|
7 |
<style>
|
|
|
8 |
.warning {
|
|
|
9 |
color: red;
|
|
|
10 |
}
|
|
|
11 |
</style>
|
|
|
12 |
<script src="../lib/jquery.js"></script>
|
|
|
13 |
<script src="../lib/jquery.mockjax.js"></script>
|
|
|
14 |
<script src="../lib/jquery.form.js"></script>
|
|
|
15 |
<script src="../dist/jquery.validate.js"></script>
|
|
|
16 |
<script>
|
|
|
17 |
jQuery(function() {
|
|
|
18 |
$.mockjax({
|
|
|
19 |
url: "login.action",
|
|
|
20 |
response: function(settings) {
|
|
|
21 |
var user = settings.data.match(/user=(.+?)($|&)/)[1],
|
|
|
22 |
password = settings.data.match(/password=(.+?)($|&)/)[1];
|
|
|
23 |
if (password !== "foobar") {
|
|
|
24 |
this.responseText = "Your password is wrong (must be foobar).";
|
|
|
25 |
return;
|
|
|
26 |
}
|
|
|
27 |
this.responseText = "Hi " + user + ", welcome back.";
|
|
|
28 |
},
|
|
|
29 |
responseStatus: 200,
|
|
|
30 |
responseTime: 500
|
|
|
31 |
});
|
|
|
32 |
|
|
|
33 |
// show a simple loading indicator
|
|
|
34 |
var loader = jQuery('<div id="loader"><img src="images/loading.gif" alt="loading..."></div>')
|
|
|
35 |
.css({
|
|
|
36 |
position: "relative",
|
|
|
37 |
top: "1em",
|
|
|
38 |
left: "25em",
|
|
|
39 |
display: "inline"
|
|
|
40 |
})
|
|
|
41 |
.appendTo("body")
|
|
|
42 |
.hide();
|
|
|
43 |
jQuery().ajaxStart(function() {
|
|
|
44 |
loader.show();
|
|
|
45 |
}).ajaxStop(function() {
|
|
|
46 |
loader.hide();
|
|
|
47 |
}).ajaxError(function(a, b, e) {
|
|
|
48 |
throw e;
|
|
|
49 |
});
|
|
|
50 |
|
|
|
51 |
var v = jQuery("#form").validate({
|
|
|
52 |
submitHandler: function(form) {
|
|
|
53 |
jQuery(form).ajaxSubmit({
|
|
|
54 |
target: "#result"
|
|
|
55 |
});
|
|
|
56 |
}
|
|
|
57 |
});
|
|
|
58 |
|
|
|
59 |
jQuery("#reset").click(function() {
|
|
|
60 |
v.resetForm();
|
|
|
61 |
});
|
|
|
62 |
});
|
|
|
63 |
</script>
|
|
|
64 |
</head>
|
|
|
65 |
<body>
|
|
|
66 |
<h1 id="banner"><a href="https://jqueryvalidation.org/">jQuery Validation Plugin</a> Demo</h1>
|
|
|
67 |
<div id="main">
|
|
|
68 |
<form method="post" class="cmxform" id="form" action="login.action">
|
|
|
69 |
<fieldset>
|
|
|
70 |
<legend>Login Form (Enter "foobar" as password)</legend>
|
|
|
71 |
<p>
|
|
|
72 |
<label for="user">Username</label>
|
|
|
73 |
<input id="user" name="user" title="Please enter your username (at least 3 characters)" class="required" minlength="3">
|
|
|
74 |
</p>
|
|
|
75 |
<p>
|
|
|
76 |
<label for="pass">Password</label>
|
|
|
77 |
<input type="password" name="password" id="password" class="required" minlength "5">
|
|
|
78 |
</p>
|
|
|
79 |
<p>
|
|
|
80 |
<input class="submit" type="submit" value="Login">
|
|
|
81 |
</p>
|
|
|
82 |
</fieldset>
|
|
|
83 |
</form>
|
|
|
84 |
<div id="result" class="warning">Please login!</div>
|
|
|
85 |
<br>
|
|
|
86 |
<button id="reset">Programmatically reset above form!</button>
|
|
|
87 |
<a href="index.html">Back to main page</a>
|
|
|
88 |
</div>
|
|
|
89 |
</body>
|
|
|
90 |
</html>
|