8000 Core: Allow the normalizer to return any value by Arkni · Pull Request #2054 · jquery-validation/jquery-validation · GitHub
[go: up one dir, main page]

Skip to content

Core: Allow the normalizer to return any value #2054

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

Merged
merged 1 commit into from
Sep 2, 2017
Merged
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
4 changes: 0 additions & 4 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -745,10 +745,6 @@ $.extend( $.validator, {
if ( normalizer ) {
val = normalizer.call( element, val );

if ( typeof val !== "string" ) {
throw new TypeError( "The normalizer should return a string value." );
}

// Delete the normalizer from rules to avoid treating it as a pre-defined method.
delete rules.normalizer;
}
Expand Down
20 changes: 6 additions & 14 deletions test/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,14 +360,11 @@ QUnit.test( "rules(), global/local normalizer", function( assert ) {
},
lastname: {
required: true,
normalizer: function( value ) {
normalizer: function() {
assert.equal( this, lastname[ 0 ], "`this` in the normalizer should be the lastname element." );

// Return null in order to make sure an exception is thrown
// when normalizer returns a non string value.
value = null;

return value;
// The normalizer can return any value
return null;
}
}
}
Expand All @@ -388,15 +385,10 @@ QUnit.test( "rules(), global/local normalizer", function( assert ) {
username.trigger( "keyup" );
urlc.trigger( "keyup" );

assert.equal( v.numberOfInvalids(), 0, "All elements are valid" );
assert.equal( v.size(), 0, "All elements are valid" );
lastname.valid();

// Validate the lastname element, which will throw an exception
assert.throws( function() {
v.check( lastname[ 0 ] );
}, function( err ) {
return err.name === "TypeError" && err.message === "The normalizer should return a string value.";
}, "This should throw a TypeError exception." );
assert.equal( v.numberOfInvalids(), 1, "Only one element is invalid" );
assert.equal( v.size(), 1, "Only one element is invalid" );
} );

QUnit.test( "rules() - on unexpected input", function( assert ) {
Expand Down
0