diff --git a/src/core.js b/src/core.js index 17b39a7..0e9b527 100644 --- a/src/core.js +++ b/src/core.js @@ -90,16 +90,19 @@ $.extend($.fn, { }, // http://jqueryvalidation.org/valid/ valid: function() { - var valid, validator; + var valid, validator, errorList; if ( $( this[ 0 ] ).is( "form" ) ) { valid = this.validate().form(); } else { + errorList = []; valid = true; validator = $( this[ 0 ].form ).validate(); this.each( function() { valid = validator.element( this ) && valid; + errorList = errorList.concat( validator.errorList ); }); + validator.errorList = errorList; } return valid; }, diff --git a/test/test.js b/test/test.js index b0efe76..64d838e 100644 --- a/test/test.js +++ b/test/test.js @@ -719,6 +719,21 @@ test( "focusInvalid()", function() { v.focusInvalid(); }); +test( "focusInvalid() after validate a custom set of inputs", function() { + var form = $( "#testForm1" ), + validator = form.validate(), + // It's important the order of Valid, Invalid, Valid so last active element it's a valid element before focus + inputs = $( "#firstname, #lastname, #something" ); + + $( "#firstname" ).val( "ok" ); + + ok( !inputs.valid(), "just one invalid"); + + validator.focusInvalid(); + + equal( form[ 0 ].ownerDocument.activeElement, $( "#lastname" )[0], "focused first element" ); +}); + test( "findLastActive()", function() { expect( 3 ); var v = $( "#testForm1" ).validate(),