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
5 changes: 4 additions & 1 deletion src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this lists only be merged in case the input/element is not valid?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if you've noticed that from a performance view. In this case is more faster to do a var reference assignment rather than:

  1. get the valid value
  2. then compare
  3. Optionally asign the var reference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I prefer don't discuss how make this fragment better. I think is better fix the problem inside of showError method, but I don't have more time for spent on this (too much time I spent for find the scenario and the source problem)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, thanks.

});
validator.errorList = errorList;
}
return valid;
},
Expand Down
15 changes: 15 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down