Skip to content

Commit b8ee9a4

Browse files
committed
Added the posibility to change position of error messages
1 parent 7d24531 commit b8ee9a4

File tree

3 files changed

+154
-35
lines changed

3 files changed

+154
-35
lines changed

example.html

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,61 @@
9898
$('#area').restrictLength($('#maxlength'));
9999
</script>
100100
<p>
101-
<input type="submit" value="Validate" />
101+
<input type="submit" value="Validate form" />
102102
</p>
103103
</form>
104104
</section>
105+
106+
<section>
107+
<form action="" id="custom_form">
108+
<p>
109+
<strong>Length between 3-5 characters</strong> <em>validate_length length3-5</em><br />
110+
<textarea data-validation="validate_length length3-5" rows="4"></textarea>
111+
</p>
112+
<p>
113+
<strong>E-mail</strong> <em>validate_email</em><br />
114+
<input data-validation="validate_email" />
115+
</p>
116+
<p>
117+
<strong>Domain</strong> <em>validate_domain</em><br />
118+
<input data-validation="validate_domain" />
119+
</p>
120+
<p>
121+
<strong>Url</strong> <em>validate_url</em><br />
122+
<input data-validation="validate_url" />
123+
</p>
124+
<p>
125+
<strong>When will you arrive</strong>
126+
<em>Buy checking this option you will have to give a valid value on the question below otherwise not</em>
127+
<input type="checkbox" name="disable_hours" checked="checked" />
128+
</p>
129+
<p>
130+
<strong>Time HH:mm</strong> <em>validate_time</em><br />
131+
<input data-validation="validate_time" name="hours" />
132+
</p>
133+
<p>
134+
<input type="submit" value="Validate form" />
135+
</p>
136+
</form>
137+
<script>
138+
var conf = {
139+
errorMessagePosition : 'element',
140+
borderColorOnError : '',
141+
ignore: []
142+
};
143+
144+
$('#custom_form').submit(function() {
145+
conf.ignore.length = 0;
146+
if($('input[name=disable_hours]').is(':checked'))
147+
conf.ignore.push('hours');
148+
149+
if($(this).validate(false, conf))
150+
alert('Valid!');
151+
152+
return false;
153+
});
154+
155+
</script>
156+
</section>
105157
</body>
106158
</html>

style.css

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ section {
2222
background:#FFF;
2323
padding: 15px 10px 10px;
2424
max-width: 500px;
25+
margin-bottom: 20px;
2526
}
2627

2728
textarea {
@@ -41,6 +42,14 @@ input, textarea {
4142
color: #666;
4243
}
4344

45+
input[type=submit] {
46+
background:#f0f8ff;
47+
font-weight:bold;
48+
color: #3e8888;
49+
width: 130px;
50+
cursor: pointer;
51+
}
52+
4453
.jquery_form_error_message {
4554
margin:5px 0 20px;
4655
padding: 10px;
@@ -53,14 +62,23 @@ input, textarea {
5362
background: pink;
5463
}
5564

56-
span.chars_left {
65+
span.chars_left
66+
span.jquery_form_error_message {
5767
background: #f2f2f2;
5868
padding: 0 2px;
5969
font-weight: normal;
6070
font-size: 90%;
6171
color: #666;
6272
}
6373

74+
span.jquery_form_error_message {
75+
color: red;
76+
display: block;
77+
background: none;
78+
margin:0;
79+
padding:0;
80+
}
81+
6482
em {
6583
background: lightyellow;
6684
font-size: 90%;

0 commit comments

Comments
 (0)