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 26, 2018
1 parent aa6c72c commit ba80f25
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/core.js
Expand Up @@ -671,9 +671,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 @@ -1024,9 +1024,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 ba80f25

Please sign in to comment.