Skip to content

Commit

Permalink
Core: find error for form elements outside of the form
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonHeimberg committed Oct 30, 2018
1 parent 2567f7d commit 0b3fbb4
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/core.js
Expand Up @@ -672,9 +672,9 @@ $.extend( $.validator, {
return $( selector )[ 0 ];
},

errors: function() {
errors: function( errorContext ) {
var errorClass = this.settings.errorClass.split( " " ).join( "." );
return $( this.settings.errorElement + "." + errorClass, this.errorContext );
return $( this.settings.errorElement + "." + errorClass, errorContext ? errorContext : this.errorContext );
},

resetInternals: function() {
Expand Down Expand Up @@ -1025,9 +1025,17 @@ $.extend( $.validator, {
.replace( /\s+/g, ", #" );
}

return this
var errors = this
.errors()
.filter( selector );

if ( errors.length === 0 && $( element ).closest( element.form ).length === 0 ) {
errors = this
.errors( $( element ).parent() )
.filter( selector );
}

return errors;
},

// See https://api.jquery.com/category/selectors/, for CSS
Expand Down

0 comments on commit 0b3fbb4

Please sign in to comment.