From a006b22a6a617e95edb187173641ee53210dc4f5 Mon Sep 17 00:00:00 2001 From: Angela Nicholas Date: Tue, 7 Oct 2014 14:10:24 -0700 Subject: [PATCH] clear buffer when shifting characters to the left --- spec/Focus.Spec.js | 17 +++++++++++++++++ src/jquery.maskedinput.js | 1 + 2 files changed, 18 insertions(+) diff --git a/spec/Focus.Spec.js b/spec/Focus.Spec.js index 9964893..de3976c 100644 --- a/spec/Focus.Spec.js +++ b/spec/Focus.Spec.js @@ -126,6 +126,23 @@ feature("Leaving A Masked Input",function(){ expect(input).toHaveValue("1_"); }); }); + + scenario("Shifts characters left on blur with autoclear false",function(){ + given("a mask with 10 placeholders",function(){ + input.mask("(999) 999-9999", { autoclear: false }); + }); + when("focusing input",function(){ + input.focus(); + }); + waits(20); + when("typing characters at the end of the mask and blurring",function(){ + input.caret(12); + input.mashKeys("44").blur(); + }); + then("characters should shift left to beginning of mask",function(){ + expect(input).toHaveValue("(44_) ___-____"); + }); + }); }); feature("Optional marker",function(){ diff --git a/src/jquery.maskedinput.js b/src/jquery.maskedinput.js index dd388f1..1350673 100644 --- a/src/jquery.maskedinput.js +++ b/src/jquery.maskedinput.js @@ -305,6 +305,7 @@ $.fn.extend({ } } if (pos > test.length) { + clearBuffer(i + 1, len); break; } } else if (buffer[i] === test.charAt(pos) && i !== partialPosition) {