From: Bartosz DziewoƄski Date: Mon, 16 Apr 2018 18:41:56 +0000 (+0200) Subject: jquery.lengthLimit: Fix 'cut'/'paste' event handling X-Git-Tag: 1.34.0-rc.0~5244^2 X-Git-Url: https://git.cyclocoop.org/%20%27.%28%24debut%20%20%20%24par_page%29.%27?a=commitdiff_plain;h=5fe159de6e91fa591846a054f5a8680d8a42d1f8;p=lhc%2Fweb%2Fwiklou.git jquery.lengthLimit: Fix 'cut'/'paste' event handling For the 'cut' and 'paste' events, the input value is only updated after the event handlers resolve. Bug: T64319 Change-Id: Ia0b85ce986eb05aceb7096c56a235477970a4d6f --- diff --git a/resources/src/jquery/jquery.lengthLimit.js b/resources/src/jquery/jquery.lengthLimit.js index 2738d1afa8..186ad17787 100644 --- a/resources/src/jquery/jquery.lengthLimit.js +++ b/resources/src/jquery/jquery.lengthLimit.js @@ -127,7 +127,8 @@ // we can trim the previous one). // See https://www.w3.org/TR/DOM-Level-3-Events/#events-keyboard-event-order for // the order and characteristics of the key events. - $el.on( eventKeys, function () { + + function enforceLimit() { var res = trimFn( prevSafeVal, this.value, @@ -149,6 +150,15 @@ // trimFn to compare the new value to an empty string instead of the // old value, resulting in trimming always from the end (T42850). prevSafeVal = res.newVal; + } + + $el.on( eventKeys, function ( e ) { + if ( e.type === 'cut' || e.type === 'paste' ) { + // For 'cut'/'paste', the input value is only updated after the event handlers resolve. + setTimeout( enforceLimit.bind( this ) ); + } else { + enforceLimit.call( this ); + } } ); } ); }