Skip to content
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
17 changes: 10 additions & 7 deletions jquery.validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ $.extend($.validator, {

// http://docs.jquery.com/Plugins/Validation/Validator/element
element: function( element ) {
element = this.clean( element );
element = this.validationTargetFor( this.clean( element ) );
this.lastElement = element;
this.prepareElement( element );
this.currentElements = $(element);
Expand Down Expand Up @@ -490,12 +490,7 @@ $.extend($.validator, {
},

check: function( element ) {
element = this.clean( element );

// if radio/checkbox, validate first element in group instead
if (this.checkable(element)) {
element = this.findByName( element.name ).not(this.settings.ignore)[0];
}
element = this.validationTargetFor( this.clean( element ) );

var rules = $(element).rules();
var dependencyMismatch = false;
Expand Down Expand Up @@ -676,6 +671,14 @@ $.extend($.validator, {
return this.groups[element.name] || (this.checkable(element) ? element.name : element.id || element.name);
},

validationTargetFor: function(element) {
// if radio/checkbox, validate first element in group instead
if (this.checkable(element)) {
element = this.findByName( element.name ).not(this.settings.ignore)[0];
}
return element;
},

checkable: function( element ) {
return /radio|checkbox/i.test(element.type);
},
Expand Down
22 changes: 22 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,28 @@ test("validate multiple checkbox on click", function() {
errors(1);
});

test("correct checkbox receives the error", function(){
function trigger(element) {
element.click();
// triggered click event screws up checked-state in 1.4
element.valid();
}
var e1 = $("#check1").attr("checked", false);
var e2 = $("#check1b").attr("checked", false);
var v = $("#form").find('[type=checkbox]').attr('checked', false).end().validate({
rules:{
check: {
required: true,
minlength: 2
}
}
});
equals(false, v.form());
trigger(e1);
equals(false, v.form());
ok(v.errorList[0].element.id === v.currentElements[0].id, "the proper checkbox has the error AND is present in currentElements");
});

test("validate radio on click", function() {
function errors(expected, message) {
equals(expected, v.size(), message );
Expand Down