Browse Source

alternationTrackback

Robin Herbots 11 years ago
parent
commit
44ff2b3914
1 changed files with 26 additions and 0 deletions
  1. 26 0
      js/jquery.inputmask.js

+ 26 - 0
js/jquery.inputmask.js

@@ -843,6 +843,31 @@
                     }
                     return false;
                 }
+                //set alternator choice on previous skipped placeholder positions
+                function trackbackAlternations(originalPos, newPos) {
+                    var vp = getMaskSet()["validPositions"][newPos],
+                        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, equality = -1;
+                            for (var tndx in tests) {
+                                var activeTest = tests[tndx];
+                                for (var i = 0; i < tll; i++) {
+                                    if (targetLocator[i] == activeTest.locator[i] && equality < i) { //needs fix for locators with multiple alternations
+                                        equality = i;
+                                        bestMatch = activeTest;
+                                    }
+                                }
+                                //console.log(bestMatch.locator);
+                            }
+                            setValidPosition(ps, $.extend({}, bestMatch, { "input": bestMatch["match"].def }), true)
+                        }
+                    }
+                }
                 //Check for a nonmask before the pos
                 var buffer = getBuffer();
                 for (var pndx = pos - 1; pndx > -1; pndx--) {
@@ -869,6 +894,7 @@
                             for (var nPos = maskPos + 1, snPos = seekNext(maskPos) ; nPos <= snPos; nPos++) {
                                 result = _isValid(nPos, c, strict, fromSetValid);
                                 if (result !== false) {
+                                    trackbackAlternations(maskPos, nPos);
                                     maskPos = nPos;
                                     break;
                                 }