Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:hidden elements ignored by default #195

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jquery.validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ $.extend($.validator, {
errorContainer: $( [] ),
errorLabelContainer: $( [] ),
onsubmit: true,
ignore: [],
ignore: ":hidden",
ignoreTitle: false,
onfocusin: function(element) {
this.lastActive = element;
Expand Down
27 changes: 27 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1137,3 +1137,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");
});