Skip to content

Instantly share code, notes, and snippets.

@gregoryagu
Created August 4, 2018 00:09
Show Gist options
  • Save gregoryagu/68ec1e23998af7aa92129c964ec56e8a to your computer and use it in GitHub Desktop.
Save gregoryagu/68ec1e23998af7aa92129c964ec56e8a to your computer and use it in GitHub Desktop.
Materialize Validation
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>GistRun</title>
<link rel="stylesheet" href="styles.css">
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/css/materialize.min.css">
<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/js/materialize.min.js"></script>
</head>
<body>
<div class="row">
<form id="signUp" class="col s6">
<div class="row">
<div class="input-field col s12">
<input id="company" name="company" type="text" required class="validate" data-error='The Team Name is Required' >
<label for="company">Team or Company Name *</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<p>
<label>
<input name="agree" type="checkbox" required class="validate"/>
<span>I agree with the terms and conditions</span>
</label>
</p>
</div>
</div>
<div class="row">
<div class="col s12">
<input id="submit" type="submit" value="Go" class="waves-effect waves-light btn">
</div>
</div>
</form>
</div>
</div>
</body>
</html>
console.log('Hello World!');
$().ready(function () {
console.log("init validation");
$("#signUp").validate({
rules: {
company: {
required: true,
minlength: 2
},
agree: {
required: true
}
},
submitHandler: function (form) { // for demo
alert('valid form submitted'); // for demo
return false; // for demo
},
errorClass: 'invalid',
errorElement: 'div',
});
});
/* todo: add styles */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment