Skip to content

Commit 2170712

Browse files
hdragomirjzaefferer
authored andcommitted
Fixed jquery-validation#189 - :hidden elements are now ignored by default
1 parent 665f67d commit 2170712

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* Fixed #184 - resetForm: should unset lastElement
1414
* Fixed #71 - improve existing time method and add time12h method for 12h am/pm time format
1515
* Fixed #177 - Fix validation of a single radio or checkbox input
16+
* Fixed #189 - :hidden elements are now ignored by default
1617

1718
1.8.1
1819
---

jquery.validate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ $.extend($.validator, {
214214
errorContainer: $( [] ),
215215
errorLabelContainer: $( [] ),
216216
onsubmit: true,
217-
ignore: [],
217+
ignore: ":hidden",
218218
ignoreTitle: false,
219219
onfocusin: function(element) {
220220
this.lastActive = element;

test/test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,3 +1159,30 @@ test("validate radio on click", function() {
11591159
trigger(e1);
11601160
errors(0);
11611161
});
1162+
1163+
test("ignore hidden elements", function(){
1164+
var form = $('#userForm');
1165+
var validate = form.validate({
1166+
rules:{
1167+
"username": "required"
1168+
}
1169+
});
1170+
form.get(0).reset();
1171+
ok(! validate.form(), "form should be initially invalid");
1172+
$('#userForm [name=username]').hide();
1173+
ok(validate.form(), "hidden elements should be ignored by default");
1174+
});
1175+
1176+
test("ignore hidden elements at start", function(){
1177+
var form = $('#userForm');
1178+
var validate = form.validate({
1179+
rules:{
1180+
"username": "required"
1181+
}
1182+
});
1183+
form.get(0).reset();
1184+
$('#userForm [name=username]').hide();
1185+
ok(validate.form(), "hidden elements should be ignored by default");
1186+
$('#userForm [name=username]').show();
1187+
ok(! validate.form(), "form should be invalid when required element is visible");
1188+
});

0 commit comments

Comments
 (0)