Robin Herbots 11 年之前
父节点
当前提交
c92e5a04c5
共有 6 个文件被更改,包括 115 次插入96 次删除
  1. 4 3
      README.md
  2. 26 20
      dist/inputmask/jquery.inputmask.js
  3. 26 20
      dist/jquery.inputmask.bundle.js
  4. 3 3
      dist/jquery.inputmask.bundle.min.js
  5. 50 47
      js/jquery.inputmask.js
  6. 6 3
      qunit/tests_base.js

+ 4 - 3
README.md

@@ -677,9 +677,10 @@ $(selector).inputmask("Regex", {
 
 #### postProcessOnBlur
 
-This is a hook todo some postprocessing of the value on the blur event, this overrides the clearOptionalTail functionality
-Args => tmpBuffer, opts
-Manipulations in the tmpBuffer are written to input element
+This is a hook todo some postprocessing of the value on the blur event.  
+Args => buffer, opts
+
+Manipulations in the buffer are written to input element
 
 ##Functions
 

+ 26 - 20
dist/inputmask/jquery.inputmask.js

@@ -237,7 +237,7 @@
                     var t = positionsClone[i];
                     if (void 0 != t) {
                         var vps = getMaskSet().validPositions;
-                        j = !opts.keepStatic && (void 0 != vps[i + 1] && getTests(i + 1, vps[i].locator.slice(), i).length > 1 || vps[i] && void 0 != vps[i].alternation) ? i + 1 : seekNext(i), 
+                        j = !opts.keepStatic && vps[i] && (void 0 != vps[i + 1] && getTests(i + 1, vps[i].locator.slice(), i).length > 1 || void 0 != vps[i].alternation) ? i + 1 : seekNext(i), 
                         valid = positionCanMatchDefinition(j, t.match.def) ? valid && isValid(j, t.input, !0, !0) !== !1 : null == t.match.fn;
                     }
                     if (!valid) break;
@@ -540,9 +540,12 @@
             resetMaskSet(), writeOut && input._valueSet("");
             var staticInput = getBufferTemplate().slice(0, seekNext(-1)).join(""), matches = inputValue.join("").match(new RegExp(escapeRegex(staticInput), "g"));
             if (matches && matches.length > 1 && inputValue.splice(0, staticInput.length), $.each(inputValue, function(ndx, charCode) {
-                var lvp = getLastValidPosition();
-                -1 == $.inArray(charCode, getBufferTemplate().slice(lvp + 1, getMaskSet().p)) || strict ? (keypressEvent.call(input, void 0, !0, charCode.charCodeAt(0), !1, strict, strict ? ndx : getMaskSet().p), 
-                strict = strict || ndx > 0 && ndx > getMaskSet().p) : keypressEvent.call(input, void 0, !0, charCode.charCodeAt(0), !1, !0, lvp + 1);
+                var lvp = getLastValidPosition(), lvTest = getMaskSet().validPositions[lvp], nextTest = getTestTemplate(lvp + 1, lvTest ? lvTest.locator.slice() : void 0, lvp);
+                if (-1 == $.inArray(charCode, getBufferTemplate().slice(lvp + 1, getMaskSet().p)) || strict) {
+                    var pos = strict ? ndx : null == nextTest.match.fn ? lvp + 1 : getMaskSet().p;
+                    keypressEvent.call(input, void 0, !0, charCode.charCodeAt(0), !1, strict, pos), 
+                    strict = strict || ndx > 0 && ndx > getMaskSet().p;
+                } else keypressEvent.call(input, void 0, !0, charCode.charCodeAt(0), !1, !0, lvp + 1);
             }), writeOut) {
                 var keypressResult = opts.onKeyPress.call(this, void 0, getBuffer(), 0, opts);
                 handleOnKeyResult(input, keypressResult), writeBuffer(input, getBuffer(), $(input).is(":focus") ? seekNext(getLastValidPosition(0)) : void 0);
@@ -602,13 +605,9 @@
                 def: positions[bl] ? positions[bl].match : void 0
             } : bl;
         }
-        function clearOptionalTail(input) {
-            var buffer = getBuffer(), tmpBuffer = buffer.slice();
-            if ($.isFunction(opts.postProcessOnBlur)) opts.postProcessOnBlur.call(input, tmpBuffer, opts); else {
-                for (var rl = determineLastRequiredPosition(), lmib = tmpBuffer.length - 1; lmib > rl && !isMask(lmib); lmib--) ;
-                tmpBuffer.splice(rl, lmib + 1 - rl);
-            }
-            writeBuffer(input, tmpBuffer);
+        function clearOptionalTail(buffer) {
+            for (var rl = determineLastRequiredPosition(), lmib = buffer.length - 1; lmib > rl && !isMask(lmib); lmib--) ;
+            buffer.splice(rl, lmib + 1 - rl);
         }
         function isComplete(buffer) {
             if ($.isFunction(opts.isComplete)) return opts.isComplete.call($el, buffer, opts);
@@ -872,12 +871,12 @@
                 }).bind("blur.inputmask", function() {
                     var $input = $(this), input = this;
                     if ($input.data("_inputmask")) {
-                        var nptValue = input._valueGet(), buffer = getBuffer();
-                        firstClick = !0, valueOnFocus != getBuffer().join("") && ($input.change(), valueOnFocus = getBuffer().join("")), 
-                        opts.clearMaskOnLostFocus && "" != nptValue && (nptValue == getBufferTemplate().join("") ? input._valueSet("") : clearOptionalTail(input)), 
+                        var nptValue = input._valueGet(), buffer = getBuffer().slice();
+                        firstClick = !0, valueOnFocus != buffer.join("") && ($input.change(), valueOnFocus = buffer.join("")), 
+                        "" != nptValue && (opts.clearMaskOnLostFocus && (nptValue == getBufferTemplate().join("") ? buffer = [] : clearOptionalTail(buffer)), 
                         isComplete(buffer) === !1 && ($input.trigger("incomplete"), opts.clearIncomplete && (resetMaskSet(), 
-                        opts.clearMaskOnLostFocus ? input._valueSet("") : (buffer = getBufferTemplate().slice(), 
-                        writeBuffer(input, buffer))));
+                        buffer = opts.clearMaskOnLostFocus ? [] : getBufferTemplate().slice())), $.isFunction(opts.postProcessOnBlur) && opts.postProcessOnBlur.call(input, buffer, opts), 
+                        writeBuffer(input, buffer));
                     }
                 }).bind("focus.inputmask", function() {
                     var input = ($(this), this), nptValue = input._valueGet();
@@ -885,7 +884,11 @@
                     valueOnFocus = getBuffer().join("");
                 }).bind("mouseleave.inputmask", function() {
                     var $input = $(this), input = this;
-                    opts.clearMaskOnLostFocus && ($input.is(":focus") || input._valueGet() == $input.attr("placeholder") || (input._valueGet() == getBufferTemplate().join("") || "" == input._valueGet() ? input._valueSet("") : clearOptionalTail(input)));
+                    if (opts.clearMaskOnLostFocus) {
+                        var buffer = getBuffer().slice(), nptValue = input._valueGet();
+                        $input.is(":focus") || nptValue == $input.attr("placeholder") || "" == nptValue || (nptValue == getBufferTemplate().join("") ? buffer = [] : clearOptionalTail(buffer), 
+                        writeBuffer(input, buffer));
+                    }
                 }).bind("click.inputmask", function() {
                     var $input = $(this), input = this;
                     if ($input.is(":focus")) {
@@ -919,13 +922,16 @@
                 "paste" === PasteEventType && $el.bind("input.inputmask", inputFallBackEvent), (android || androidfirefox || androidchrome || kindle) && ($el.unbind("input.inputmask"), 
                 $el.bind("input.inputmask", mobileInputEvent)), patchValueProperty(el);
                 var initialValue = $.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call(el, el._valueGet(), opts) || el._valueGet() : el._valueGet();
-                checkVal(el, !0, !1, initialValue.split("")), valueOnFocus = getBuffer().join("");
+                checkVal(el, !0, !1, initialValue.split(""));
+                var buffer = getBuffer().slice();
+                valueOnFocus = buffer.join("");
                 var activeElement;
                 try {
                     activeElement = document.activeElement;
                 } catch (e) {}
-                isComplete(getBuffer()) === !1 && opts.clearIncomplete && resetMaskSet(), opts.clearMaskOnLostFocus ? getBuffer().join("") == getBufferTemplate().join("") ? el._valueSet("") : clearOptionalTail(el) : writeBuffer(el, getBuffer()), 
-                activeElement === el && caret(el, seekNext(getLastValidPosition())), installEventRuler(el);
+                isComplete(buffer) === !1 && opts.clearIncomplete && resetMaskSet(), opts.clearMaskOnLostFocus && (buffer.join("") == getBufferTemplate().join("") ? buffer = [] : clearOptionalTail(buffer)), 
+                writeBuffer(el, buffer), activeElement === el && caret(el, seekNext(getLastValidPosition())), 
+                installEventRuler(el);
             }
         }
         var valueOnFocus, $el, maxLength, isRTL = !1, skipKeyPressEvent = !1, skipInputEvent = !1, ignorable = !1, firstClick = !0;

+ 26 - 20
dist/jquery.inputmask.bundle.js

@@ -235,7 +235,7 @@
                     var t = positionsClone[i];
                     if (void 0 != t) {
                         var vps = getMaskSet().validPositions;
-                        j = !opts.keepStatic && (void 0 != vps[i + 1] && getTests(i + 1, vps[i].locator.slice(), i).length > 1 || vps[i] && void 0 != vps[i].alternation) ? i + 1 : seekNext(i), 
+                        j = !opts.keepStatic && vps[i] && (void 0 != vps[i + 1] && getTests(i + 1, vps[i].locator.slice(), i).length > 1 || void 0 != vps[i].alternation) ? i + 1 : seekNext(i), 
                         valid = positionCanMatchDefinition(j, t.match.def) ? valid && isValid(j, t.input, !0, !0) !== !1 : null == t.match.fn;
                     }
                     if (!valid) break;
@@ -538,9 +538,12 @@
             resetMaskSet(), writeOut && input._valueSet("");
             var staticInput = getBufferTemplate().slice(0, seekNext(-1)).join(""), matches = inputValue.join("").match(new RegExp(escapeRegex(staticInput), "g"));
             if (matches && matches.length > 1 && inputValue.splice(0, staticInput.length), $.each(inputValue, function(ndx, charCode) {
-                var lvp = getLastValidPosition();
-                -1 == $.inArray(charCode, getBufferTemplate().slice(lvp + 1, getMaskSet().p)) || strict ? (keypressEvent.call(input, void 0, !0, charCode.charCodeAt(0), !1, strict, strict ? ndx : getMaskSet().p), 
-                strict = strict || ndx > 0 && ndx > getMaskSet().p) : keypressEvent.call(input, void 0, !0, charCode.charCodeAt(0), !1, !0, lvp + 1);
+                var lvp = getLastValidPosition(), lvTest = getMaskSet().validPositions[lvp], nextTest = getTestTemplate(lvp + 1, lvTest ? lvTest.locator.slice() : void 0, lvp);
+                if (-1 == $.inArray(charCode, getBufferTemplate().slice(lvp + 1, getMaskSet().p)) || strict) {
+                    var pos = strict ? ndx : null == nextTest.match.fn ? lvp + 1 : getMaskSet().p;
+                    keypressEvent.call(input, void 0, !0, charCode.charCodeAt(0), !1, strict, pos), 
+                    strict = strict || ndx > 0 && ndx > getMaskSet().p;
+                } else keypressEvent.call(input, void 0, !0, charCode.charCodeAt(0), !1, !0, lvp + 1);
             }), writeOut) {
                 var keypressResult = opts.onKeyPress.call(this, void 0, getBuffer(), 0, opts);
                 handleOnKeyResult(input, keypressResult), writeBuffer(input, getBuffer(), $(input).is(":focus") ? seekNext(getLastValidPosition(0)) : void 0);
@@ -600,13 +603,9 @@
                 def: positions[bl] ? positions[bl].match : void 0
             } : bl;
         }
-        function clearOptionalTail(input) {
-            var buffer = getBuffer(), tmpBuffer = buffer.slice();
-            if ($.isFunction(opts.postProcessOnBlur)) opts.postProcessOnBlur.call(input, tmpBuffer, opts); else {
-                for (var rl = determineLastRequiredPosition(), lmib = tmpBuffer.length - 1; lmib > rl && !isMask(lmib); lmib--) ;
-                tmpBuffer.splice(rl, lmib + 1 - rl);
-            }
-            writeBuffer(input, tmpBuffer);
+        function clearOptionalTail(buffer) {
+            for (var rl = determineLastRequiredPosition(), lmib = buffer.length - 1; lmib > rl && !isMask(lmib); lmib--) ;
+            buffer.splice(rl, lmib + 1 - rl);
         }
         function isComplete(buffer) {
             if ($.isFunction(opts.isComplete)) return opts.isComplete.call($el, buffer, opts);
@@ -870,12 +869,12 @@
                 }).bind("blur.inputmask", function() {
                     var $input = $(this), input = this;
                     if ($input.data("_inputmask")) {
-                        var nptValue = input._valueGet(), buffer = getBuffer();
-                        firstClick = !0, valueOnFocus != getBuffer().join("") && ($input.change(), valueOnFocus = getBuffer().join("")), 
-                        opts.clearMaskOnLostFocus && "" != nptValue && (nptValue == getBufferTemplate().join("") ? input._valueSet("") : clearOptionalTail(input)), 
+                        var nptValue = input._valueGet(), buffer = getBuffer().slice();
+                        firstClick = !0, valueOnFocus != buffer.join("") && ($input.change(), valueOnFocus = buffer.join("")), 
+                        "" != nptValue && (opts.clearMaskOnLostFocus && (nptValue == getBufferTemplate().join("") ? buffer = [] : clearOptionalTail(buffer)), 
                         isComplete(buffer) === !1 && ($input.trigger("incomplete"), opts.clearIncomplete && (resetMaskSet(), 
-                        opts.clearMaskOnLostFocus ? input._valueSet("") : (buffer = getBufferTemplate().slice(), 
-                        writeBuffer(input, buffer))));
+                        buffer = opts.clearMaskOnLostFocus ? [] : getBufferTemplate().slice())), $.isFunction(opts.postProcessOnBlur) && opts.postProcessOnBlur.call(input, buffer, opts), 
+                        writeBuffer(input, buffer));
                     }
                 }).bind("focus.inputmask", function() {
                     var input = ($(this), this), nptValue = input._valueGet();
@@ -883,7 +882,11 @@
                     valueOnFocus = getBuffer().join("");
                 }).bind("mouseleave.inputmask", function() {
                     var $input = $(this), input = this;
-                    opts.clearMaskOnLostFocus && ($input.is(":focus") || input._valueGet() == $input.attr("placeholder") || (input._valueGet() == getBufferTemplate().join("") || "" == input._valueGet() ? input._valueSet("") : clearOptionalTail(input)));
+                    if (opts.clearMaskOnLostFocus) {
+                        var buffer = getBuffer().slice(), nptValue = input._valueGet();
+                        $input.is(":focus") || nptValue == $input.attr("placeholder") || "" == nptValue || (nptValue == getBufferTemplate().join("") ? buffer = [] : clearOptionalTail(buffer), 
+                        writeBuffer(input, buffer));
+                    }
                 }).bind("click.inputmask", function() {
                     var $input = $(this), input = this;
                     if ($input.is(":focus")) {
@@ -917,13 +920,16 @@
                 "paste" === PasteEventType && $el.bind("input.inputmask", inputFallBackEvent), (android || androidfirefox || androidchrome || kindle) && ($el.unbind("input.inputmask"), 
                 $el.bind("input.inputmask", mobileInputEvent)), patchValueProperty(el);
                 var initialValue = $.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call(el, el._valueGet(), opts) || el._valueGet() : el._valueGet();
-                checkVal(el, !0, !1, initialValue.split("")), valueOnFocus = getBuffer().join("");
+                checkVal(el, !0, !1, initialValue.split(""));
+                var buffer = getBuffer().slice();
+                valueOnFocus = buffer.join("");
                 var activeElement;
                 try {
                     activeElement = document.activeElement;
                 } catch (e) {}
-                isComplete(getBuffer()) === !1 && opts.clearIncomplete && resetMaskSet(), opts.clearMaskOnLostFocus ? getBuffer().join("") == getBufferTemplate().join("") ? el._valueSet("") : clearOptionalTail(el) : writeBuffer(el, getBuffer()), 
-                activeElement === el && caret(el, seekNext(getLastValidPosition())), installEventRuler(el);
+                isComplete(buffer) === !1 && opts.clearIncomplete && resetMaskSet(), opts.clearMaskOnLostFocus && (buffer.join("") == getBufferTemplate().join("") ? buffer = [] : clearOptionalTail(buffer)), 
+                writeBuffer(el, buffer), activeElement === el && caret(el, seekNext(getLastValidPosition())), 
+                installEventRuler(el);
             }
         }
         var valueOnFocus, $el, maxLength, isRTL = !1, skipKeyPressEvent = !1, skipInputEvent = !1, ignorable = !1, firstClick = !0;

文件差异内容过多而无法显示
+ 3 - 3
dist/jquery.inputmask.bundle.min.js


+ 50 - 47
js/jquery.inputmask.js

@@ -402,7 +402,7 @@
                         var t = positionsClone[i];
                         if (t != undefined) {
                             var vps = getMaskSet()["validPositions"];
-                            if (!opts.keepStatic && (vps[i + 1] != undefined && getTests(i + 1, vps[i].locator.slice(), i).length > 1 || (vps[i] && vps[i].alternation != undefined)))
+                            if (!opts.keepStatic && vps[i] && (vps[i + 1] != undefined && getTests(i + 1, vps[i].locator.slice(), i).length > 1 || vps[i].alternation != undefined))
                                 j = i + 1;
                             else
                                 j = seekNext(i);
@@ -847,19 +847,17 @@
                          targetLocator = vp.locator,
                          tll = targetLocator.length;
 
-                    //console.log("target locator: " + targetLocator);
                     for (var ps = originalPos; ps < newPos; ps++) {
                         if (!isMask(ps)) {
                             var tests = getTests(ps),
                             bestMatch = tests[0], equality = -1;
-                            $.each(tests, function(ndx, tst) {
+                            $.each(tests, function (ndx, tst) {
                                 for (var i = 0; i < tll; i++) {
                                     if (tst.locator[i] && checkAlternationMatch(tst.locator[i].toString().split(','), targetLocator[i].toString().split(',')) && equality < i) {
                                         equality = i;
                                         bestMatch = tst;
                                     }
                                 }
-                                //console.log(bestMatch.locator);
                             });
                             setValidPosition(ps, $.extend({}, bestMatch, { "input": bestMatch["match"].def }), true)
                         }
@@ -967,9 +965,10 @@
                 }
 
                 $.each(inputValue, function (ndx, charCode) {
-                    var lvp = getLastValidPosition();
+                    var lvp = getLastValidPosition(), lvTest = getMaskSet()["validPositions"][lvp], nextTest = getTestTemplate(lvp + 1, lvTest ? lvTest.locator.slice() : undefined, lvp);
                     if ($.inArray(charCode, getBufferTemplate().slice(lvp + 1, getMaskSet()["p"])) == -1 || strict) {
-                        keypressEvent.call(input, undefined, true, charCode.charCodeAt(0), false, strict, strict ? ndx : getMaskSet()["p"]);
+                        var pos = strict ? ndx : (nextTest["match"].fn == null ? lvp + 1 : getMaskSet()["p"]);
+                        keypressEvent.call(input, undefined, true, charCode.charCodeAt(0), false, strict, pos);
                         strict = strict || (ndx > 0 && ndx > getMaskSet()["p"]);
                     } else {
                         keypressEvent.call(input, undefined, true, charCode.charCodeAt(0), false, true, lvp + 1);
@@ -1079,18 +1078,12 @@
                 }
                 return returnDefinition ? { "l": bl, "def": positions[bl] ? positions[bl]["match"] : undefined } : bl;
             }
-            function clearOptionalTail(input) {
-                var buffer = getBuffer(), tmpBuffer = buffer.slice();
-                if ($.isFunction(opts.postProcessOnBlur))
-                    opts.postProcessOnBlur.call(input, tmpBuffer, opts);
-                else {
-                    var rl = determineLastRequiredPosition(), lmib = tmpBuffer.length - 1;
-                    for (; lmib > rl; lmib--) {
-                        if (isMask(lmib)) break;
-                    }
-                    tmpBuffer.splice(rl, lmib + 1 - rl);
+            function clearOptionalTail(buffer) {
+                var rl = determineLastRequiredPosition(), lmib = buffer.length - 1;
+                for (; lmib > rl; lmib--) {
+                    if (isMask(lmib)) break;
                 }
-                writeBuffer(input, tmpBuffer);
+                buffer.splice(rl, lmib + 1 - rl);
             }
             function isComplete(buffer) { //return true / false / undefined (repeat *)
                 if ($.isFunction(opts.isComplete)) return opts.isComplete.call($el, buffer, opts);
@@ -1611,30 +1604,38 @@
                     }).bind("blur.inputmask", function () {
                         var $input = $(this), input = this;
                         if ($input.data('_inputmask')) {
-                            var nptValue = input._valueGet(), buffer = getBuffer();
+                            var nptValue = input._valueGet(), buffer = getBuffer().slice();
                             firstClick = true;
-                            if (valueOnFocus != getBuffer().join('')) {
+                            if (valueOnFocus != buffer.join('')) {
                                 $input.change();
-                                valueOnFocus = getBuffer().join('');
+                                valueOnFocus = buffer.join('');
                             }
-                            if (opts.clearMaskOnLostFocus && nptValue != '') {
-                                if (nptValue == getBufferTemplate().join(''))
-                                    input._valueSet('');
-                                else { //clearout optional tail of the mask
-                                    clearOptionalTail(input);
+                            if (nptValue != '') {
+                                if (opts.clearMaskOnLostFocus) {
+                                    if (nptValue == getBufferTemplate().join(''))
+                                        buffer = [];
+                                    else { //clearout optional tail of the mask
+                                        clearOptionalTail(buffer);
+                                    }
                                 }
-                            }
-                            if (isComplete(buffer) === false) {
-                                $input.trigger("incomplete");
-                                if (opts.clearIncomplete) {
-                                    resetMaskSet();
-                                    if (opts.clearMaskOnLostFocus)
-                                        input._valueSet('');
-                                    else {
-                                        buffer = getBufferTemplate().slice();
-                                        writeBuffer(input, buffer);
+                                if (isComplete(buffer) === false) {
+                                    $input.trigger("incomplete");
+                                    if (opts.clearIncomplete) {
+                                        resetMaskSet();
+                                        if (opts.clearMaskOnLostFocus)
+                                            buffer = [];
+                                        else {
+                                            buffer = getBufferTemplate().slice();
+
+                                        }
                                     }
                                 }
+
+                                if ($.isFunction(opts.postProcessOnBlur)) {
+                                    opts.postProcessOnBlur.call(input, buffer, opts);
+                                }
+
+                                writeBuffer(input, buffer);
                             }
                         }
                     }).bind("focus.inputmask", function (e) {
@@ -1648,12 +1649,14 @@
                     }).bind("mouseleave.inputmask", function () {
                         var $input = $(this), input = this;
                         if (opts.clearMaskOnLostFocus) {
-                            if (!$input.is(":focus") && input._valueGet() != $input.attr("placeholder")) {
-                                if (input._valueGet() == getBufferTemplate().join('') || input._valueGet() == '')
-                                    input._valueSet('');
+                            var buffer = getBuffer().slice(), nptValue = input._valueGet();
+                            if (!$input.is(":focus") && nptValue != $input.attr("placeholder") && nptValue != '') {
+                                if (nptValue == getBufferTemplate().join(''))
+                                    buffer = [];
                                 else { //clearout optional tail of the mask
-                                    clearOptionalTail(input);
+                                    clearOptionalTail(buffer);
                                 }
+                                writeBuffer(input, buffer);
                             }
                         }
                     }).bind("click.inputmask", function () {
@@ -1723,26 +1726,26 @@
                     //apply mask
                     var initialValue = $.isFunction(opts.onBeforeMask) ? (opts.onBeforeMask.call(el, el._valueGet(), opts) || el._valueGet()) : el._valueGet();
                     checkVal(el, true, false, initialValue.split(''));
-                    valueOnFocus = getBuffer().join('');
+                    var buffer = getBuffer().slice();
+                    valueOnFocus = buffer.join('');
                     // Wrap document.activeElement in a try/catch block since IE9 throw "Unspecified error" if document.activeElement is undefined when we are in an IFrame.
                     var activeElement;
                     try {
                         activeElement = document.activeElement;
                     } catch (e) {
                     }
-                    if (isComplete(getBuffer()) === false) {
+                    if (isComplete(buffer) === false) {
                         if (opts.clearIncomplete)
                             resetMaskSet();
                     }
                     if (opts.clearMaskOnLostFocus) {
-                        if (getBuffer().join('') == getBufferTemplate().join('')) {
-                            el._valueSet('');
+                        if (buffer.join('') == getBufferTemplate().join('')) {
+                            buffer = [];
                         } else {
-                            clearOptionalTail(el);
+                            clearOptionalTail(buffer);
                         }
-                    } else {
-                        writeBuffer(el, getBuffer());
                     }
+                    writeBuffer(el, buffer);
                     if (activeElement === el) { //position the caret when in focus
                         caret(el, seekNext(getLastValidPosition()));
                     }
@@ -1937,7 +1940,7 @@
                 //specify keyCodes which should not be considered in the keypress event, otherwise the preventDefault will stop their default behavior especially in FF
                 ignorables: [8, 9, 13, 19, 27, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46, 93, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123],
                 isComplete: undefined, //override for isComplete - args => buffer, opts - return true || false
-                postProcessOnBlur: undefined //do some postprocessing of the value on the blur event, this overrides the clearOptionalTail functionality, args => tmpBuffer, opts
+                postProcessOnBlur: undefined //do some postprocessing of the value on the blur event, args => tmpBuffer, opts
             },
             keyCode: {
                 ALT: 18, BACKSPACE: 8, CAPS_LOCK: 20, COMMA: 188, COMMAND: 91, COMMAND_LEFT: 91, COMMAND_RIGHT: 93, CONTROL: 17, DELETE: 46, DOWN: 40, END: 35, ENTER: 13, ESCAPE: 27, HOME: 36, INSERT: 45, LEFT: 37, MENU: 93, NUMPAD_ADD: 107, NUMPAD_DECIMAL: 110, NUMPAD_DIVIDE: 111, NUMPAD_ENTER: 108,

+ 6 - 3
qunit/tests_base.js

@@ -10,14 +10,17 @@ test("inputmask(\"99-99-99\", { clearMaskOnLostFocus: false}", function () {
     $("#testmask").remove();
 });
 
-test("inputmask(\"99-99-99\", { clearMaskOnLostFocus: true}", function () {
+asyncTest("inputmask(\"99-99-99\", { clearMaskOnLostFocus: true}", function () {
     var $fixture = $("#qunit-fixture");
     $fixture.append('<input type="text" id="testmask" />');
     $("#testmask").inputmask("99-99-99", { clearMaskOnLostFocus: true });
     $("#testmask").blur();
-    equal(document.getElementById("testmask").value, "", "Result " + document.getElementById("testmask").value);
+    setTimeout(function () {
+        start();
+        equal(document.getElementById("testmask").value, "", "Result " + document.getElementById("testmask").value);
 
-    $("#testmask").remove();
+        $("#testmask").remove();
+    }, 0);
 });
 
 test("inputmask(\"999.999.999\")", function () {