From d3748a2271223be1c23742dbf79dd918eb2158ee Mon Sep 17 00:00:00 2001 From: Brighton Balfrey Date: Wed, 13 May 2020 13:47:44 -0700 Subject: [PATCH] Core: Fixes deprecated calls to jQuery trim (#2328) Fixes #2327 Co-authored-by: Brighton Balfrey --- src/core.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/core.js b/src/core.js index ccb8d4cbe..b7b8f3b9b 100644 --- a/src/core.js +++ b/src/core.js @@ -198,18 +198,25 @@ $.extend( $.fn, { } } ); +// JQuery trim is deprecated, provide a trim method based on String.prototype.trim +var trim = function( str ) { + + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim#Polyfill + return str.replace( /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, "" ); +}; + // Custom selectors $.extend( $.expr.pseudos || $.expr[ ":" ], { // '|| $.expr[ ":" ]' here enables backwards compatibility to jQuery 1.7. Can be removed when dropping jQ 1.7.x support // https://jqueryvalidation.org/blank-selector/ blank: function( a ) { - return !$.trim( "" + $( a ).val() ); + return !trim( "" + $( a ).val() ); }, // https://jqueryvalidation.org/filled-selector/ filled: function( a ) { var val = $( a ).val(); - return val !== null && !!$.trim( "" + val ); + return val !== null && !!trim( "" + val ); }, // https://jqueryvalidation.org/unchecked-selector/