Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reset errors with "remote" validation #2150 #2191

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/core.js
Expand Up @@ -912,9 +912,16 @@ $.extend( $.validator, {
},

invalidElements: function() {
return $( this.errorList ).map( function() {
return this.element;
var
v = this,
invalid = $.extend( {}, v.invalid ),
$elements = $( [] );
$.each( invalid, function( key, value ) {
if ( value !== false && invalid.hasOwnProperty( key ) ) {
$elements = $elements.add( v.findByName( key ) );
}
} );
return $elements;
},

showLabel: function( element, message ) {
Expand Down Expand Up @@ -1532,7 +1539,7 @@ $.extend( $.validator, {
method = typeof method === "string" && method || "remote";

var previous = this.previousValue( element, method ),
validator, data, optionDataString;
validator, data, optionDataString, result = "pending";

if ( !this.settings.messages[ element.name ] ) {
this.settings.messages[ element.name ] = {};
Expand Down Expand Up @@ -1577,11 +1584,13 @@ $.extend( $.validator, {
validator.invalid[ element.name ] = true;
validator.showErrors( errors );
}
previous.valid = valid;

// Fix for QUnit test "remote" method with ajax immediate callback
result = previous.valid = valid;
validator.stopRequest( element, valid );
}
}, param ) );
return "pending";
return result;
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/methods.js
Expand Up @@ -708,7 +708,7 @@ QUnit.test( "remote, highlight all invalid fields", function( assert ) {
}, 500 );
} );
QUnit.test( "remote, unhighlighted should be invoked after being highlighted/invalid", function( assert ) {
assert.expect( 6 );
assert.expect( 7 );

var done1 = assert.async(),
done2 = assert.async(),
Expand Down
4 changes: 2 additions & 2 deletions test/rules.js
Expand Up @@ -374,10 +374,10 @@ QUnit.test( "rules(), global/local normalizer", function( assert ) {

// Validate only the username and the url elements.
username.valid();
assert.equal( v.invalidElements()[ 0 ], username[ 0 ], "The username should be invalid" );
assert.equal( v.invalidElements().filter( username )[ 0 ], username[ 0 ], "The username should be invalid" );

urlc.valid();
assert.equal( v.invalidElements()[ 0 ], urlc[ 0 ], "The url should be invalid" );
assert.equal( v.invalidElements().filter( urlc )[ 0 ], urlc[ 0 ], "The url should be invalid" );

assert.equal( v.numberOfInvalids(), 2, "There is two invalid elements" );

Expand Down