Robin Herbots 11 年 前
コミット
f67cf13d0e

+ 4 - 3
dist/inputmask/jquery.inputmask.js

@@ -541,7 +541,7 @@
             if (matches && matches.length > 1 && inputValue.splice(0, staticInput.length), $.each(inputValue, function(ndx, charCode) {
                 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;
+                    var pos = strict ? ndx : null == nextTest.match.fn && lvp + 1 < getMaskSet().p ? 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);
@@ -800,8 +800,9 @@
                 } else isSlctn && (getMaskSet().buffer = void 0, getMaskSet().validPositions = getMaskSet().undoPositions);
                 if (opts.showTooltip && $input.prop("title", getMaskSet().mask), e && e.preventDefault(), 
                 checkval) {
-                    var keyResult = opts.onKeyPress.call(this, e, getBuffer(), -1, opts);
-                    keyResult && (handleOnKeyResult(input, keyResult), getMaskSet().p = getLastValidPosition() + 1);
+                    var keyResult = opts.onKeyPress.call(this, e, getBuffer(), forwardPosition, opts);
+                    keyResult && keyResult.refreshFromBuffer && (handleOnKeyResult(input, keyResult), 
+                    keyResult.caret && (getMaskSet().p = keyResult.caret));
                 } else {
                     var currentCaretPos = caret(input);
                     handleOnKeyResult(input, opts.onKeyPress.call(this, e, getBuffer(), currentCaretPos.begin, opts), currentCaretPos);

+ 4 - 3
dist/jquery.inputmask.bundle.js

@@ -539,7 +539,7 @@
             if (matches && matches.length > 1 && inputValue.splice(0, staticInput.length), $.each(inputValue, function(ndx, charCode) {
                 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;
+                    var pos = strict ? ndx : null == nextTest.match.fn && lvp + 1 < getMaskSet().p ? 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);
@@ -798,8 +798,9 @@
                 } else isSlctn && (getMaskSet().buffer = void 0, getMaskSet().validPositions = getMaskSet().undoPositions);
                 if (opts.showTooltip && $input.prop("title", getMaskSet().mask), e && e.preventDefault(), 
                 checkval) {
-                    var keyResult = opts.onKeyPress.call(this, e, getBuffer(), -1, opts);
-                    keyResult && (handleOnKeyResult(input, keyResult), getMaskSet().p = getLastValidPosition() + 1);
+                    var keyResult = opts.onKeyPress.call(this, e, getBuffer(), forwardPosition, opts);
+                    keyResult && keyResult.refreshFromBuffer && (handleOnKeyResult(input, keyResult), 
+                    keyResult.caret && (getMaskSet().p = keyResult.caret));
                 } else {
                     var currentCaretPos = caret(input);
                     handleOnKeyResult(input, opts.onKeyPress.call(this, e, getBuffer(), currentCaretPos.begin, opts), currentCaretPos);

ファイルの差分が大きいため隠しています
+ 2 - 2
dist/jquery.inputmask.bundle.min.js


+ 5 - 4
js/jquery.inputmask.js

@@ -967,7 +967,7 @@
                 $.each(inputValue, function (ndx, charCode) {
                     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) {
-                        var pos = strict ? ndx : (nextTest["match"].fn == null ? lvp + 1 : getMaskSet()["p"]);
+                        var pos = strict ? ndx : (nextTest["match"].fn == null && (lvp + 1) < getMaskSet()["p"] ? lvp + 1 : getMaskSet()["p"]);
                         keypressEvent.call(input, undefined, true, charCode.charCodeAt(0), false, strict, pos);
                         strict = strict || (ndx > 0 && ndx > getMaskSet()["p"]);
                     } else {
@@ -1444,10 +1444,11 @@
 
                         if (e) e.preventDefault();
                         if (checkval) {
-                            var keyResult = opts.onKeyPress.call(this, e, getBuffer(), -1, opts);
-                            if (keyResult) {
+                            var keyResult = opts.onKeyPress.call(this, e, getBuffer(), forwardPosition, opts);
+                            if (keyResult && keyResult["refreshFromBuffer"]) {
                                 handleOnKeyResult(input, keyResult);
-                                getMaskSet()["p"] = getLastValidPosition() + 1;
+                                if (keyResult.caret)
+                                    getMaskSet()["p"] = keyResult.caret;
                             }
                         } else {
                             var currentCaretPos = caret(input);

+ 1 - 0
qunit/tests_numeric.js

@@ -934,6 +934,7 @@ test("inputmask(\"decimal\") - 8100000.00 digitsoptional false - ManRueda", func
     });
 
     $("#testmask").val(8100000.00);
+    $("#testmask").blur();
 
     equal($("#testmask").val(), "810.000,00", "Result " + $("#testmask").val());
     $("#testmask").remove();