Skip to content

Commit

Permalink
Fixed jquery-validation#189 - :hidden elements are now ignored by def…
Browse files Browse the repository at this point in the history
…ault
  • Loading branch information
hdragomir authored and mlynch committed Mar 27, 2012
1 parent 98422e9 commit 6d364ec
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.txt
Expand Up @@ -13,6 +13,7 @@
* Fixed #184 - resetForm: should unset lastElement
* Fixed #71 - improve existing time method and add time12h method for 12h am/pm time format
* Fixed #177 - Fix validation of a single radio or checkbox input
* Fixed #189 - :hidden elements are now ignored by default

1.8.1
---
Expand Down
2 changes: 1 addition & 1 deletion jquery.validate.js
Expand Up @@ -214,7 +214,7 @@ $.extend($.validator, {
errorContainer: $( [] ),
errorLabelContainer: $( [] ),
onsubmit: true,
ignore: [],
ignore: ":hidden",
ignoreTitle: false,
onfocusin: function(element, event) {
this.lastActive = element;
Expand Down
27 changes: 27 additions & 0 deletions test/test.js
Expand Up @@ -1159,3 +1159,30 @@ test("validate radio on click", function() {
trigger(e1);
errors(0);
});

test("ignore hidden elements", function(){
var form = $('#userForm');
var validate = form.validate({
rules:{
"username": "required"
}
});
form.get(0).reset();
ok(! validate.form(), "form should be initially invalid");
$('#userForm [name=username]').hide();
ok(validate.form(), "hidden elements should be ignored by default");
});

test("ignore hidden elements at start", function(){
var form = $('#userForm');
var validate = form.validate({
rules:{
"username": "required"
}
});
form.get(0).reset();
$('#userForm [name=username]').hide();
ok(validate.form(), "hidden elements should be ignored by default");
$('#userForm [name=username]').show();
ok(! validate.form(), "form should be invalid when required element is visible");
});

0 comments on commit 6d364ec

Please sign in to comment.