From 5fe159de6e91fa591846a054f5a8680d8a42d1f8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Mon, 16 Apr 2018 20:41:56 +0200 Subject: [PATCH] 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 --- resources/src/jquery/jquery.lengthLimit.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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 ); + } } ); } ); } -- 2.20.1