Skip to content

Commit 2db4ea4

Browse files
authored
Fixed oldVal being updated prior to caret position calculation
Fixed an issue that's occurring in at least Chrome 74. Symptoms were the same as #602.
1 parent 9244e3f commit 2db4ea4

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/jquery.mask.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,8 @@
187187

188188
return r;
189189
},
190-
calculateCaretPosition: function() {
191-
var oldVal = el.data('mask-previus-value') || '',
192-
newVal = p.getMasked(),
190+
calculateCaretPosition: function(oldVal='') {
191+
var newVal = p.getMasked(),
193192
caretPosNew = p.getCaret();
194193
if (oldVal !== newVal) {
195194
var caretPosOld = el.data('mask-previus-caret-pos') || 0,
@@ -255,12 +254,13 @@
255254

256255
if ($.inArray(keyCode, jMask.byPassKeys) === -1) {
257256
var newVal = p.getMasked(),
258-
caretPos = p.getCaret();
257+
caretPos = p.getCaret(),
258+
oldVal = el.data('mask-previus-value');
259259

260260
// this is a compensation to devices/browsers that don't compensate
261261
// caret positioning the right way
262262
setTimeout(function() {
263-
p.setCaret(p.calculateCaretPosition());
263+
p.setCaret(p.calculateCaretPosition(oldVal));
264264
}, $.jMaskGlobals.keyStrokeCompensation);
265265

266266
p.val(newVal);

0 commit comments

Comments
 (0)