PageRenderTime 16ms CodeModel.GetById 1ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/jquery-validate/demo/themerollered.html

#
HTML | 227 lines | 210 code | 17 blank | 0 comment | 0 complexity | 67de8d30b94377251e50e1761f6a10db MD5 | raw file
  1<!DOCTYPE html>
  2<html>
  3<head>
  4<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
  5<title>jQuery validation plug-in - main demo</title>
  6
  7<link rel="stylesheet" type="text/css" media="screen" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/cupertino/jquery-ui.css" />
  8<link rel="stylesheet" type="text/css" media="screen" href="http://jquery-ui.googlecode.com/svn/branches/dev/themes/base/ui.button.css" />
  9
 10<script src="../lib/jquery.js" type="text/javascript"></script>
 11<script src="../jquery.validate.js" type="text/javascript"></script>
 12
 13<script src="http://jquery-ui.googlecode.com/svn/tags/latest/ui/jquery.ui.core.js" type="text/javascript"></script>
 14<script src="http://jquery-ui.googlecode.com/svn/tags/latest/ui/jquery.ui.widget.js" type="text/javascript"></script>
 15<script src="http://jquery-ui.googlecode.com/svn/tags/latest/ui/jquery.ui.button.js" type="text/javascript"></script>
 16
 17<script type="text/javascript" src="http://jqueryui.com/themeroller/themeswitchertool/"></script>
 18
 19<script type="text/javascript">
 20$.validator.setDefaults({
 21	submitHandler: function() { alert("submitted!"); },
 22	highlight: function(input) {
 23		$(input).addClass("ui-state-highlight");
 24	},
 25	unhighlight: function(input) {
 26		$(input).removeClass("ui-state-highlight");
 27	}
 28});
 29
 30$().ready(function() {
 31	$.fn.themeswitcher && $('<div/>').css({
 32		position: "absolute",
 33		right: 10,
 34		top: 10
 35	}).appendTo(document.body).themeswitcher();
 36	
 37	// validate the comment form when it is submitted
 38	$("#commentForm").validate();
 39	
 40	// validate signup form on keyup and submit
 41	$("#signupForm").validate({
 42		rules: {
 43			firstname: "required",
 44			lastname: "required",
 45			username: {
 46				required: true,
 47				minlength: 2
 48			},
 49			password: {
 50				required: true,
 51				minlength: 5
 52			},
 53			confirm_password: {
 54				required: true,
 55				minlength: 5,
 56				equalTo: "#password"
 57			},
 58			email: {
 59				required: true,
 60				email: true
 61			},
 62			topic: {
 63				required: "#newsletter:checked",
 64				minlength: 2
 65			},
 66			agree: "required"
 67		},
 68		messages: {
 69			firstname: "Please enter your firstname",
 70			lastname: "Please enter your lastname",
 71			username: {
 72				required: "Please enter a username",
 73				minlength: "Your username must consist of at least 2 characters"
 74			},
 75			password: {
 76				required: "Please provide a password",
 77				minlength: "Your password must be at least 5 characters long"
 78			},
 79			confirm_password: {
 80				required: "Please provide a password",
 81				minlength: "Your password must be at least 5 characters long",
 82				equalTo: "Please enter the same password as above"
 83			},
 84			email: "Please enter a valid email address",
 85			agree: "Please accept our policy"
 86		}
 87	});
 88	
 89	// propose username by combining first- and lastname
 90	$("#username").focus(function() {
 91		var firstname = $("#firstname").val();
 92		var lastname = $("#lastname").val();
 93		if(firstname && lastname && !this.value) {
 94			this.value = firstname + "." + lastname;
 95		}
 96	});
 97	
 98	//code to hide topic selection, disable for demo
 99	var newsletter = $("#newsletter");
100	// newsletter topics are optional, hide at first
101	var inital = newsletter.is(":checked");
102	var topics = $("#newsletter_topics")[inital ? "removeClass" : "addClass"]("gray");
103	var topicInputs = topics.find("input").attr("disabled", !inital);
104	// show when newsletter is checked
105	newsletter.click(function() {
106		topics[this.checked ? "removeClass" : "addClass"]("gray");
107		topicInputs.attr("disabled", !this.checked);
108	});
109	
110	$("#signupForm input:not(:submit)").addClass("ui-widget-content");
111	
112	$(":submit").button();
113});
114</script>
115
116<style type="text/css">
117body { font-size: 62.5%; }
118label { display: inline-block; width: 100px; }
119legend { padding: 0.5em; }
120fieldset fieldset label { display: block; }
121#commentForm { width: 500px; }
122#commentForm label { width: 250px; }
123#commentForm label.error, #commentForm button.submit { margin-left: 253px; }
124#signupForm { width: 670px; }
125#signupForm label.error {
126	margin-left: 10px;
127	width: auto;
128	display: inline;
129}
130#newsletter_topics label.error {
131	display: none;
132	margin-left: 103px;
133}
134</style>
135
136</head>
137<body>
138
139<form class="cmxform" id="commentForm" method="get" action="">
140	<fieldset class="ui-widget ui-widget-content ui-corner-all">
141		<legend class="ui-widget ui-widget-header ui-corner-all">Please provide your name, email address (won't be published) and a comment</legend>
142		<p>
143			<label for="cname">Name (required, at least 2 characters)</label>
144			<input id="cname" name="name" class="required ui-widget-content" minlength="2" />
145		<p>
146			<label for="cemail">E-Mail (required)</label>
147			<input id="cemail" name="email" class="required email ui-widget-content" />
148		</p>
149		<p>
150			<label for="curl">URL (optional)</label>
151			<input id="curl" name="url" class="url ui-widget-content" value="" />
152		</p>
153		<p>
154			<label for="ccomment">Your comment (required)</label>
155			<textarea id="ccomment" name="comment" class="required ui-widget-content"></textarea>
156		</p>
157		<p>
158			<button class="submit" type="submit">Submit</button>
159		</p>
160	</fieldset>
161</form>
162
163<form class="cmxform" id="signupForm" method="get" action="">
164	<fieldset class="ui-widget ui-widget-content ui-corner-all">
165		<legend class="ui-widget ui-widget-header ui-corner-all">Validating a complete form</legend>
166		<p>
167			<label for="firstname">Firstname</label>
168			<input id="firstname" name="firstname" />
169		</p>
170		<p>
171			<label for="lastname">Lastname</label>
172			<input id="lastname" name="lastname" />
173		</p>
174		<p>
175			<label for="username">Username</label>
176			<input id="username" name="username" />
177		</p>
178		<p>
179			<label for="password">Password</label>
180			<input id="password" name="password" type="password" />
181		</p>
182		<p>
183			<label for="confirm_password">Confirm password</label>
184			<input id="confirm_password" name="confirm_password" type="password" />
185		</p>
186		<p>
187			<label for="email">Email</label>
188			<input id="email" name="email" />
189		</p>
190		<p>
191			<label for="agree">Please agree to our policy</label>
192			<input type="checkbox" class="checkbox" id="agree" name="agree" />
193		</p>
194		<p>
195			<label for="newsletter">I'd like to receive the newsletter</label>
196			<input type="checkbox" class="checkbox" id="newsletter" name="newsletter" />
197		</p>
198		<fieldset id="newsletter_topics" class="ui-widget-content ui-corner-all">
199			<legend class="ui-widget-header ui-corner-all">Topics (select at least two) - note: would be hidden when newsletter isn't selected, but is visible here for the demo</legend>
200			<label for="topic_marketflash">
201				<input type="checkbox" id="topic_marketflash" value="marketflash" name="topic" />
202				Marketflash
203			</label>
204			<label for="topic_fuzz">
205				<input type="checkbox" id="topic_fuzz" value="fuzz" name="topic" />
206				Latest fuzz
207			</label>
208			<label for="topic_digester">
209				<input type="checkbox" id="topic_digester" value="digester" name="topic" />
210				Mailing list digester
211			</label>
212			<label for="topic" class="error">Please select at least two topics you'd like to receive.</label>
213		</fieldset>
214		<p>
215			<button class="submit" type="submit">Submit</button>
216		</p>
217	</fieldset>
218</form>
219
220<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
221</script>
222<script type="text/javascript">
223_uacct = "UA-2623402-1";
224urchinTracker();
225</script>
226</body>
227</html>