Skip to content

Instantly share code, notes, and snippets.

@zitterbewegung
Created June 6, 2012 13:57
Show Gist options
  • Select an option

  • Save zitterbewegung/2882005 to your computer and use it in GitHub Desktop.

Select an option

Save zitterbewegung/2882005 to your computer and use it in GitHub Desktop.
Question about validate.js
from bottle import Bottle, route, run, static_file, post
@route('/static/<filename>')
def server_static(filename):
return static_file(filename, root='.')
@post('/post')
'''What do I do here? '''
def post():
return ""
run(host='localhost', port=8080, debug=True)
<!DOCTYPE html>
<html lang="en">
<head>
<title>validate.js</title>
<meta name="description" content="Lightweight form validation library in JavaScript ready to include in any web application." />
<link href="http://fonts.googleapis.com/css?family=Andada" rel="stylesheet" type="text/css">
<link href="styles/main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript" src="validate.min.js"></script>
</head>
<body>
<h1>validate.js</h1>
<div id="content">
<div style="clear:both;"></div>
<h3><span>Example</span></h3>
<div class="success_box">All of the fields were successfully validated!</div>
<div class="error_box"></div>
<form name="example_form" action="/post" method="POST">
<label for="req">Required field:</label>
<label for="alphanumeric">Alphanumeric field:</label>
<input name="req" id="req" />
<input name="alphanumeric" id="alphanumeric" />
<label for="password">Password:</label>
<label for="password_confirm">Password Confirmation (match password):</label>
<input name="password" id="password" type="password" />
<input name="password_confirm" id="password_confirm" type="password" />
<label for="email">Email:</label>
<label for="minlength">Min length field (min. 8 chars):</label>
<input name="email" id="email" />
<input name="minlength" id="minlength" />
<label for="hostname">Hostname: </label>
<label for="ipv4" id="ipv4" />
<input name="ipv4" id="ipv4" />
<label for="tos_checkbox">Required checkbox (example: Terms of Service)</label>
<input name="tos_checkbox" id="tos_checkbox" type="checkbox" />
<button class="button gray" type="submit" name="submit">Submit</button>
</form>
<script type="text/javascript">
new FormValidator('example_form', [{
name: 'req',
display: 'required',
rules: 'required'
}, {
name: 'alphanumeric',
rules: 'alpha_numeric'
}, {
name: 'password',
rules: 'required'
}, {
name: 'password_confirm',
display: 'password confirmation',
rules: 'required|matches[password]'
}, {
name: 'email',
rules: 'valid_email'
}, {
name: 'hostname',
display: 'required',
rules: 'required|alpha_numeric'
}, {
name: 'ipv4'
display: 'required',
rules: 'valid_ip'
}, {
name: 'tos_checkbox',
display: 'terms of service',
rules: 'required'
}], function(errors, event) {
var SELECTOR_ERRORS = $('.error_box'),
SELECTOR_SUCCESS = $('.success_box');
if (errors.length > 0) {
SELECTOR_ERRORS.empty();
for (var i = 0, errorLength = errors.length; i < errorLength; i++) {
SELECTOR_ERRORS.append(errors[i].message + '<br />');
}
SELECTOR_SUCCESS.css({ display: 'none' });
SELECTOR_ERRORS.fadeIn(200);
} else {
SELECTOR_ERRORS.css({ display: 'none' });
SELECTOR_SUCCESS.fadeIn(200);
}
if (event && event.preventDefault) {
event.preventDefault();
} else if (event) {
event.returnValue = false;
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment