Skip to content

Fix regressions introduced in #1644 and #1657 #1800

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

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
15 changes: 15 additions & 0 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,20 @@ $.extend( $.validator, {
return undefined;
},

// The second parameter 'rule' used to be a string, and extended to an object literal
// of the following form:
// rule = {
// method: "method name",
// parameters: "the given method parameters"
// }
//
// The old behavior still supported, kept to maintain backward compatibility with
// old code, and will be removed in the next major release.
defaultMessage: function( element, rule ) {
if ( typeof rule === "string" ) {
rule = { method: rule };
}

var message = this.findDefined(
this.customMessage( element.name, rule.method ),
this.customDataMessage( element, rule.method ),
Expand Down Expand Up @@ -1067,6 +1080,8 @@ $.extend( $.validator, {
},

previousValue: function( element, method ) {
method = typeof method === "string" && method || "remote";

return $.data( element, "previousValue" ) || $.data( element, "previousValue", {
old: null,
valid: true,
Expand Down
24 changes: 24 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,30 @@ test( "option: errorClass with multiple classes", function() {
test( "defaultMessage(), empty title is ignored", function() {
var v = $( "#userForm" ).validate();
equal( v.defaultMessage( $( "#username" )[ 0 ], { method: "required", parameters: true } ), "This field is required." );

// Using the old way when we pass the name of a method as the second parameters.
equal( v.defaultMessage( $( "#username" )[ 0 ], "required" ), "This field is required." );
} );

QUnit.test( "previousValue()", function( assert ) {
assert.expect( 2 );

var e = $( "#username" ),
v = $( "#userForm" ).validate(),
expectedRemote = {
old: null,
valid: true,
message: "Please fix this field."
}, expectedRequired = {
old: null,
valid: true,
message: "This field is required."
};

assert.deepEqual( v.previousValue( e[ 0 ] ), expectedRemote, "should be the same" );

e.removeData( "previousValue" );
assert.deepEqual( v.previousValue( e[ 0 ], "required" ), expectedRequired, "should be the same" );
} );

test( "#741: move message processing from formatAndAdd to defaultMessage", function() {
Expand Down