forked from soitgoes/FormWarden
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validation_and_visibility.html
84 lines (78 loc) · 2.39 KB
/
validation_and_visibility.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE HTML>
<html>
<head>
<script src="jquery-1.6.1.min.js" type="text/javascript"></script>
<script src="formwarden.js" type="text/javascript"></script>
<script src="jquery.formwarden.js" type="text/javascript"></script>
<style>
.invalid input{
border:solid 2px #f00;
}
.invalid{
color:#f00;
}
</style>
</head>
<body>
<form >
<p>
<label>Email: <input type="text" name="email" /></label>
</p>
<p>
<label>First Name: <input type="text" name="firstName" /></label>
</p>
<p>
<label>UserName: <input type="text" name="userName" /></label>
</p>
<p>
<label>InnCode: <input type="text" name="inncode" /></label>
</p>
<p>
<select name="select">
<option value="">select one...</option>
<option>visible</option>
<option>invisible</option>
</select>
</p>
<p>
<input type="radio" name="radio" value="1" /> Choice 1
<input type="radio" name="radio" value="2" /> Choice 2
</p>
<p>
<input type="checkbox" name="check" value="1" /> Choice A
<input type="checkbox" name="check" value="2" /> Choice B
</p>
<ul class="validation_summary">
</ul>
<input id="submit_button" type="submit" value="Go" name="submit_button"/>
</form>
<script type="text/javascript">
$(function(){
var validationOptions=
{
//override the error processing
//processErrors: function(errors){ for(var error in errors){ alert(errors[error]);}},
//disable/enable blur
//enableBlur:false, //defaults to true
//provide custom validators if desired
validators : {"inncode":function(value,form){return value.match(/^\d{5}$/);}}, //not required
fields:{
"inncode":{
validations:[
{isValid:"required", message:"Inncode is required"}
,{isValid:"inncode", message:"Inncode must be 5 digits"}
]
,isVisible:function(form){return form.select === "visible";}
},
"firstName":{
validations:[
{isValid:"maxLength", length:25, message:"First Name may not exceed 25 characters"}
]
}
}
};
$("form").validation(validationOptions);
});
</script>
</body>
</html>