浏览代码

numeric temp fixes

Robin Herbots 7 年之前
父节点
当前提交
08a12f09ff
共有 4 个文件被更改,包括 43 次插入14 次删除
  1. 1 0
      CHANGELOG.md
  2. 2 4
      js/inputmask.js
  3. 20 10
      js/inputmask.numeric.extensions.js
  4. 20 0
      qunit/tests_numeric.js

+ 1 - 0
CHANGELOG.md

@@ -5,6 +5,7 @@
 ### Updates
 ### Updates
 
 
 ### Fixed
 ### Fixed
+- digits: 3 - error on transform #2022
 - "Can not read property 'join' of undefined" when using Inputmask.format #2019
 - "Can not read property 'join' of undefined" when using Inputmask.format #2019
 - Inputmask numeric does no round up when digits is 0 #2018
 - Inputmask numeric does no round up when digits is 0 #2018
 - Strange Calendar popup issue in IE Only when used with Daterangepicker #1965
 - Strange Calendar popup issue in IE Only when used with Daterangepicker #1965

+ 2 - 4
js/inputmask.js

@@ -1642,6 +1642,7 @@
 
 
             //fill in best positions according the current input
             //fill in best positions according the current input
             function trackbackPositions(originalPos, newPos, fillOnly) {
             function trackbackPositions(originalPos, newPos, fillOnly) {
+                console.log("trackbackPositions");
                 var result;
                 var result;
                 if (originalPos === undefined) {
                 if (originalPos === undefined) {
                     //find previous valid
                     //find previous valid
@@ -1660,6 +1661,7 @@
                                 "input": getPlaceholder(ps, bestMatch.match, true) || bestMatch.match.def
                                 "input": getPlaceholder(ps, bestMatch.match, true) || bestMatch.match.def
                             });
                             });
                             bestMatch.generatedInput = true;
                             bestMatch.generatedInput = true;
+//                            console.log("trackbackPositions " + bestMatch.input);
                             revalidateMask(ps, bestMatch, true);
                             revalidateMask(ps, bestMatch, true);
                             if (fillOnly !== true) {
                             if (fillOnly !== true) {
                                 //revalidate the new position to update the locator value
                                 //revalidate the new position to update the locator value
@@ -1804,10 +1806,6 @@
                 return position;
                 return position;
             }
             }
 
 
-            function getBufferElement(position) {
-                return getMaskSet().validPositions[position] === undefined ? getPlaceholder(position) : getMaskSet().validPositions[position].input;
-            }
-
             function writeBuffer(input, buffer, caretPos, event, triggerEvents) {
             function writeBuffer(input, buffer, caretPos, event, triggerEvents) {
                 if (event && $.isFunction(opts.onBeforeWrite)) {
                 if (event && $.isFunction(opts.onBeforeWrite)) {
                     //    buffer = buffer.slice(); //prevent uncontrolled manipulation of the internal buffer
                     //    buffer = buffer.slice(); //prevent uncontrolled manipulation of the internal buffer

+ 20 - 10
js/inputmask.numeric.extensions.js

@@ -554,20 +554,30 @@
                         initialValue = initialValue.replace(".", opts.radixPoint);
                         initialValue = initialValue.replace(".", opts.radixPoint);
                     }
                     }
                 }
                 }
-                var kommaMatches = initialValue.match(/,/g);
-                var dotMatches = initialValue.match(/\./g);
-                if (dotMatches && kommaMatches) {
-                    if (dotMatches.length > kommaMatches.length) {
-                        initialValue = initialValue.replace(/\./g, "");
+                var kommaMatches = initialValue.match(/,/g) || [],
+                    dotMatches = initialValue.match(/\./g) || [];
+                if (dotMatches.length > kommaMatches.length && kommaMatches.length !== 0) {
+                    initialValue = initialValue.replace(/\./g, "");
+                    if (opts.radixPoint !== "")
                         initialValue = initialValue.replace(",", opts.radixPoint);
                         initialValue = initialValue.replace(",", opts.radixPoint);
-                    } else if (kommaMatches.length > dotMatches.length) {
-                        initialValue = initialValue.replace(/,/g, "");
+                } else if (kommaMatches.length > dotMatches.length && dotMatches.length !== 0) {
+                    initialValue = initialValue.replace(/,/g, "");
+                    if (opts.radixPoint !== "")
                         initialValue = initialValue.replace(".", opts.radixPoint);
                         initialValue = initialValue.replace(".", opts.radixPoint);
-                    } else { //equal
-                        initialValue = initialValue.indexOf(".") < initialValue.indexOf(",") ? initialValue.replace(/\./g, "") : initialValue.replace(/,/g, "");
+                } else if (kommaMatches === dotMatches) {
+                    if (initialValue.indexOf(".") < initialValue.indexOf(",")) {
+                        initialValue = initialValue.replace(/\./g, "");
+                        if (opts.radixPoint !== "")
+                            initialValue = initialValue.replace(",", opts.radixPoint);
+                    } else {
+                        initialValue = initialValue.replace(/,/g, "");
+                        if (opts.radixPoint !== "")
+                            initialValue = initialValue.replace(".", opts.radixPoint);
                     }
                     }
                 } else {
                 } else {
-                    initialValue = initialValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), "");
+
+                    initialValue = initialValue.replace(new RegExp(Inputmask.escapeRegex(initialValue.indexOf("0") === 0 ? opts.radixPoint : opts.groupSeparator), "g"), "");
+                    initialValue = initialValue.replace(new RegExp(Inputmask.escapeRegex(initialValue.indexOf("0") === 0 ? opts.radixPoint : opts.groupSeparator), "g"), "");
                 }
                 }
 
 
                 var digits = 0;
                 var digits = 0;

+ 20 - 0
qunit/tests_numeric.js

@@ -2085,4 +2085,24 @@ export default function (qunit, Inputmask) {
 
 
         assert.equal(testmask.value, "124", "Result " + testmask.value);
         assert.equal(testmask.value, "124", "Result " + testmask.value);
     });
     });
+
+    qunit.test("set 0.001 - ghost", function (assert) {
+        var $fixture = $("#qunit-fixture");
+        $fixture.append('<input type="text" id="testmask" value="0.001"/>');
+        var testmask = document.getElementById("testmask");
+        Inputmask("numeric", {
+            digits: 3,
+            digitsOptional: false,
+            suffix: ' €',
+            rightAlign: 0,
+            groupSeparator: '.',
+            radixPoint: ',',
+            placeholder: '0',
+            autoGroup: true,
+            autoUnmask: true,
+            removeMaskOnSubmit: true,
+        }).mask(testmask);
+
+        assert.equal(testmask.value, "0,001", "Result " + testmask.value);
+    });
 };
 };