Skip to content

Commit 3f841f4

Browse files
committed
fix
1 parent 29938d3 commit 3f841f4

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

js/jquery.validationEngine.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@
679679
}
680680
}
681681
// If the rules required is not added, an empty field is not validated
682-
if(!required && field.val().length < 1) options.isError = false;
682+
if(!required && field.val() && field.val().length < 1) options.isError = false;
683683

684684
// Hack for radio/checkbox group button, the validation go into the
685685
// first radio/checkbox of the group

tests/issue493

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Issue #451</title>
5+
<meta charset="UTF-8" />
6+
<link rel="stylesheet" type="text/css" href="../css/validationEngine.jquery.css" />
7+
<script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script>
8+
<script type="text/javascript" src="../js/languages/jquery.validationEngine-en.js"></script>
9+
<script type="text/javascript" src="../js/jquery.validationEngine.js"></script>
10+
<script type="text/javascript">
11+
$(document).ready(function() {
12+
13+
$('#id1').validationEngine('validate');
14+
});
15+
</script>
16+
</head>
17+
<body>
18+
19+
<p>
20+
See <a href="https://github.com/posabsolute/jQuery-Validation-Engine/issues/493">https://github.com/posabsolute/jQuery-Validation-Engine/issues/493</a>
21+
for information.
22+
</p>
23+
<form id="form">
24+
<label for="id1">
25+
ID1
26+
</label>
27+
<input id="id1" name="id1" class="validate[required]" type="text"/>
28+
</form>
29+
</body>
30+
</html>

tests/issue507.html

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Issue #430: Do not validate empty fields that is not required.</title>
5+
<meta charset="UTF-8" />
6+
<link rel="stylesheet" type="text/css" href="../css/validationEngine.jquery.css" />
7+
<script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script>
8+
<script type="text/javascript" src="../js/languages/jquery.validationEngine-en.js"></script>
9+
<script type="text/javascript" src="../js/jquery.validationEngine.js"></script>
10+
<script type="text/javascript">
11+
$(document).ready(function () {
12+
13+
$("#f").submit(function (event) {
14+
event.preventDefault();
15+
return false;
16+
});
17+
18+
$("#f").validationEngine({
19+
20+
customFunctions : {
21+
v : function(field, rules, i, options) {
22+
if ($("#f").length === 0) {
23+
return options.allrules.required.alertText;
24+
}
25+
}
26+
}
27+
28+
});
29+
30+
31+
});
32+
</script>
33+
</head>
34+
<body>
35+
<form id="f" style="margin:100px;">
36+
<!-- Note that the select has no 'options', and we want a custom function to validate it -->
37+
<select id="s" class="validate[funcCall[v]]"></select>
38+
<input id="i" type="submit"></input>
39+
</form>
40+
</html>

0 commit comments

Comments
 (0)