Browse Source

fix alignment + trackbackPositions

Robin Herbots 7 years ago
parent
commit
6b6e5050ab
2 changed files with 24 additions and 28 deletions
  1. 15 21
      js/inputmask.js
  2. 9 7
      js/inputmask.numeric.extensions.js

+ 15 - 21
js/inputmask.js

@@ -1625,7 +1625,7 @@
                 return result;
             }
 
-//fill in best positions according the current input
+            //fill in best positions according the current input
             function trackbackPositions(originalPos, newPos, fillOnly) {
                 var result;
                 if (originalPos === undefined) {
@@ -1638,27 +1638,21 @@
                     if (getMaskSet().validPositions[ps] === undefined && !isMask(ps, true)) {
                         var vp = ps == 0 ? getTest(ps) : getMaskSet().validPositions[ps - 1];
                         if (vp) {
-                            var targetLocator = getLocator(vp), tests = getTests(ps).slice(),
-                                tstLocator, closest = undefined, bestMatch = getTest(ps);
-                            if (tests[tests.length - 1].match.def === "") tests.pop(); //remove stop from matches
-                            $.each(tests, function (ndx, tst) { //find best matching
-                                tstLocator = getLocator(tst, targetLocator.length);
-                                var distance = Math.abs(tstLocator - targetLocator);
-                                if ((closest === undefined || distance < closest) && tst.match.fn === null && tst.match.optionality !== true && tst.match.optionalQuantifier !== true) {
-                                    closest = distance;
-                                    bestMatch = tst;
+                            var tests = getTests(ps).slice()
+                            if (tests[tests.length - 1].match.def === "") tests.pop();
+                            var bestMatch = determineTestTemplate(ps, tests);
+                            if (true || bestMatch.match.jit === undefined) {
+                                bestMatch = $.extend({}, bestMatch, {
+                                    "input": getPlaceholder(ps, bestMatch.match, true) || bestMatch.match.def
+                                });
+                                bestMatch.generatedInput = true;
+                                revalidateMask(ps, bestMatch, true);
+                                if (fillOnly !== true) {
+                                    //revalidate the new position to update the locator value
+                                    var cvpInput = getMaskSet().validPositions[newPos].input;
+                                    getMaskSet().validPositions[newPos] = undefined;
+                                    result = isValid(newPos, cvpInput, true, true);
                                 }
-                            });
-                            bestMatch = $.extend({}, bestMatch, {
-                                "input": getPlaceholder(ps, bestMatch.match, true) || bestMatch.match.def
-                            });
-                            bestMatch.generatedInput = true;
-                            revalidateMask(ps, bestMatch, true);
-                            if (fillOnly !== true) {
-                                //revalidate the new position to update the locator value
-                                var cvpInput = getMaskSet().validPositions[newPos].input;
-                                getMaskSet().validPositions[newPos] = undefined;
-                                result = isValid(newPos, cvpInput, true, true);
                             }
                         }
                     }

+ 9 - 7
js/inputmask.numeric.extensions.js

@@ -36,13 +36,15 @@
     }
 
     function alignDigits(buffer, opts) {
-        var radixPosition = $.inArray(opts.radixPoint, buffer);
-        if (radixPosition === -1) {
-            buffer.push(opts.radixPoint);
-            radixPosition = buffer.length - 1;
-        }
-        for (var i = 1; i <= opts.digits; i++) {
-            buffer[radixPosition + i] = buffer[radixPosition + i] || "0";
+        if (opts.numericInput) {
+            var radixPosition = $.inArray(opts.radixPoint, buffer);
+            if (radixPosition === -1) {
+                buffer.push(opts.radixPoint);
+                radixPosition = buffer.length - 1;
+            }
+            for (var i = 1; i <= opts.digits; i++) {
+                buffer[radixPosition + i] = buffer[radixPosition + i] || "0";
+            }
         }
         return buffer;
     }