浏览代码

fix in isvalid

Robin Herbots 11 年之前
父节点
当前提交
4c25b38b4a
共有 1 个文件被更改,包括 14 次插入11 次删除
  1. 14 11
      js/jquery.inputmask.js

+ 14 - 11
js/jquery.inputmask.js

@@ -137,7 +137,7 @@
                 if (currentToken.matches.length > 0)
                     maskTokens.push(currentToken);
 
-                console.log(JSON.stringify(maskTokens));
+                //console.log(JSON.stringify(maskTokens));
                 return maskTokens;
             }
             function generateMask(mask, metadata) {
@@ -244,13 +244,15 @@
             function getMaskSet() {
                 return maskset;
             }
-            function resetMaskSet() {
+            function resetMaskSet(soft) {
                 var maskset = getMaskSet();
                 maskset["buffer"] = undefined;
-                maskset["_buffer"] = undefined;
-                maskset["validPositions"] = {};
                 maskset["tests"] = {};
-                maskset["p"] = -1;
+                if (soft !== true) {
+                    maskset["_buffer"] = undefined;
+                    maskset["validPositions"] = {};
+                    maskset["p"] = -1;
+                }
             }
             function getLastValidPosition(closestTo) { //TODO implement closest to
                 var maskset = getMaskSet();
@@ -298,13 +300,14 @@
                     var t = getMaskSet()["validPositions"][i];
                     var s = getMaskSet()["validPositions"][startPos];
                     if (t != undefined && s == undefined) {
+                        console.log(JSON.stringify(getTest(startPos)));
                         if (getTest(startPos).def == t.match.def && isValid(startPos, t["input"], false) !== false) {
                             delete getMaskSet()["validPositions"][i];
                         }
                         startPos = seekNext(startPos);
                     }
                 }
-                getMaskSet()["buffer"] = undefined;
+                resetMaskSet(true);
             }
             function getTest(pos) {
                 if (getMaskSet()['validPositions'][pos]) {
@@ -334,9 +337,9 @@
                                     var isFirstMatch = (optionalToken.matches.indexOf(latestMatch) == 0);
                                     if (isFirstMatch) {
                                         insertStop = true; //insert a stop for non greedy
-                                        //search for next possible match
-                                        testPos = currentPos;
                                     }
+                                    //search for next possible match
+                                    testPos = currentPos;
                                 }
                             } else if (match.isQuantifier && quantifierRecurse !== true) {
                                 var qt = match;
@@ -410,7 +413,7 @@
                     matches.push({ "match": { fn: null, cardinality: 0, optionality: true, casing: null, def: "" }, "locator": [] });
 
                 getMaskSet()['tests'][pos] = matches;
-                console.log(pos + " - " + JSON.stringify(matches));
+                //console.log(pos + " - " + JSON.stringify(matches));
                 return matches;
             }
             function getBufferTemplate() {
@@ -444,12 +447,12 @@
                         //return is false or a json object => { pos: ??, c: ??} or true
                         rslt = test.fn != null ?
                             test.fn.test(chrs, buffer, position, strict, opts)
-                            : (c == test["def"] || c == opts.skipOptionalPartCharacter) ?
+                            : (c == test["def"] || c == opts.skipOptionalPartCharacter) && test["def"] != "" ? //non mask
                                 { c: test["def"], pos: position }
                                 : false;
 
                         if (rslt !== false) {
-                            var elem = c;
+                            var elem = c == opts.skipOptionalPartCharacter ? test["def"] : c;
                             switch (test.casing) {
                                 case "upper":
                                     elem = elem.toUpperCase();