mirror of
https://github.com/jquery-validation/jquery-validation.git
synced 2025-12-14 20:35:47 +01:00
Merge pull request #1609 from Arkni/transformation-layer
Core: Added transformation/normalization layer
This commit is contained in:
20
src/core.js
20
src/core.js
@@ -626,6 +626,22 @@ $.extend( $.validator, {
|
||||
val = this.elementValue( element ),
|
||||
result, method, rule;
|
||||
|
||||
// If a normalizer is defined for this element, then
|
||||
// call it to retreive the changed value instead
|
||||
// of using the real one.
|
||||
// Note that `this` in the normalizer is `element`.
|
||||
if ( typeof rules.normalizer === "function" ) {
|
||||
val = rules.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;
|
||||
}
|
||||
|
||||
for ( method in rules ) {
|
||||
rule = { method: method, parameters: rules[ method ] };
|
||||
try {
|
||||
@@ -860,7 +876,7 @@ $.extend( $.validator, {
|
||||
// meta-characters that should be escaped in order to be used with JQuery
|
||||
// as a literal part of a name/id or any selector.
|
||||
escapeCssMeta: function( string ) {
|
||||
return string.replace( /(!|"|#|\$|%|&|'|\(|\)|\*|\+|,|\.|\/|:|;|<|=|>|\?|@|\[|\\|\]|\^|`|\{|\||\}|~)/g, "\\$1");
|
||||
return string.replace( /([\\!"#$%&'()*+,./:;<=>?@\[\]^`{|}~])/g, "\\$1" );
|
||||
},
|
||||
|
||||
idOrName: function( element ) {
|
||||
@@ -1103,7 +1119,7 @@ $.extend( $.validator, {
|
||||
|
||||
// evaluate parameters
|
||||
$.each( rules, function( rule, parameter ) {
|
||||
rules[ rule ] = $.isFunction( parameter ) ? parameter( element ) : parameter;
|
||||
rules[ rule ] = $.isFunction( parameter ) && rule !== "normalizer" ? parameter( element ) : parameter;
|
||||
} );
|
||||
|
||||
// clean number parameters
|
||||
|
||||
Reference in New Issue
Block a user