Robin Herbots 7 years ago
parent
commit
5d3aeafeb2
2 changed files with 23 additions and 17 deletions
  1. 1 0
      CHANGELOG.md
  2. 22 17
      js/inputmask.js

+ 1 - 0
CHANGELOG.md

@@ -29,6 +29,7 @@
 - rename androidHack option to disablePredictiveText. Make it available for other platforms.
 - rename androidHack option to disablePredictiveText. Make it available for other platforms.
 
 
 ### Fixed
 ### Fixed
+- Android 6 issue - Samsung device keyboard #1818
 - Method oncomplete doesn't work correctly with jitMasking #1845
 - Method oncomplete doesn't work correctly with jitMasking #1845
 - isComplete in numeric extensions doesn't take into account negationSymbol #1844
 - isComplete in numeric extensions doesn't take into account negationSymbol #1844
 - Email alias - retype @ removes last . #1324
 - Email alias - retype @ removes last . #1324

+ 22 - 17
js/inputmask.js

@@ -328,7 +328,7 @@
                         if (element.indexOf("[") === 0 || (escaped && /\\d|\\s|\\w]/i.test(element)) || element === ".") {
                         if (element.indexOf("[") === 0 || (escaped && /\\d|\\s|\\w]/i.test(element)) || element === ".") {
                             mtoken.matches.splice(position++, 0, {
                             mtoken.matches.splice(position++, 0, {
                                 fn: new RegExp(element, opts.casing ? "i" : ""),
                                 fn: new RegExp(element, opts.casing ? "i" : ""),
-                                optionality: mtoken.isOptional,
+                                optionality: false,
                                 newBlockMarker: prevMatch === undefined || prevMatch.def !== element,
                                 newBlockMarker: prevMatch === undefined || prevMatch.def !== element,
                                 casing: null,
                                 casing: null,
                                 def: element,
                                 def: element,
@@ -341,7 +341,7 @@
                                 prevMatch = mtoken.matches[position - 1];
                                 prevMatch = mtoken.matches[position - 1];
                                 mtoken.matches.splice(position++, 0, {
                                 mtoken.matches.splice(position++, 0, {
                                     fn: null,
                                     fn: null,
-                                    optionality: mtoken.isOptional,
+                                    optionality: false,
                                     newBlockMarker: prevMatch === undefined || (prevMatch.def !== lmnt && prevMatch.fn !== null),
                                     newBlockMarker: prevMatch === undefined || (prevMatch.def !== lmnt && prevMatch.fn !== null),
                                     casing: null,
                                     casing: null,
                                     def: opts.staticDefinitionSymbol || lmnt,
                                     def: opts.staticDefinitionSymbol || lmnt,
@@ -358,7 +358,7 @@
                                 fn: maskdef.validator ? typeof maskdef.validator == "string" ? new RegExp(maskdef.validator, opts.casing ? "i" : "") : new function () {
                                 fn: maskdef.validator ? typeof maskdef.validator == "string" ? new RegExp(maskdef.validator, opts.casing ? "i" : "") : new function () {
                                     this.test = maskdef.validator;
                                     this.test = maskdef.validator;
                                 } : new RegExp("."),
                                 } : new RegExp("."),
-                                optionality: mtoken.isOptional,
+                                optionality: false,
                                 newBlockMarker: prevMatch === undefined || prevMatch.def !== (maskdef.definitionSymbol || element),
                                 newBlockMarker: prevMatch === undefined || prevMatch.def !== (maskdef.definitionSymbol || element),
                                 casing: maskdef.casing,
                                 casing: maskdef.casing,
                                 def: maskdef.definitionSymbol || element,
                                 def: maskdef.definitionSymbol || element,
@@ -368,7 +368,7 @@
                         } else {
                         } else {
                             mtoken.matches.splice(position++, 0, {
                             mtoken.matches.splice(position++, 0, {
                                 fn: null,
                                 fn: null,
-                                optionality: mtoken.isOptional,
+                                optionality: false,
                                 newBlockMarker: prevMatch === undefined || (prevMatch.def !== element && prevMatch.fn !== null),
                                 newBlockMarker: prevMatch === undefined || (prevMatch.def !== element && prevMatch.fn !== null),
                                 casing: null,
                                 casing: null,
                                 def: opts.staticDefinitionSymbol || element,
                                 def: opts.staticDefinitionSymbol || element,
@@ -914,14 +914,14 @@
                     }
                     }
                 }
                 }
 
 
-                // var controlPos = determineTestTemplate2(pos, tests, guessNextBest);
-                //
-                // if (controlPos != testPos) {
-                //     // debugger;
-                //     console.log(pos + " 1) " + JSON.stringify(testPos));
-                //     console.log(pos + " 2) " + JSON.stringify(controlPos));
-                //
-                // }
+                var controlPos = determineTestTemplate2(pos, tests, guessNextBest);
+
+                if (controlPos != testPos) {
+                    // debugger;
+                    console.log(pos + " 1) " + JSON.stringify(testPos));
+                    console.log(pos + " 2) " + JSON.stringify(controlPos));
+                    determineTestTemplate2(pos, tests, guessNextBest);
+                }
 
 
                 return testPos;
                 return testPos;
             }
             }
@@ -936,7 +936,7 @@
 
 
             function getLocator(tst, align) { //need to align the locators to be correct
             function getLocator(tst, align) { //need to align the locators to be correct
                 var locator = (tst.alternation != undefined ? tst.mloc[getDecisionTaker(tst)] : tst.locator).join("");
                 var locator = (tst.alternation != undefined ? tst.mloc[getDecisionTaker(tst)] : tst.locator).join("");
-                while (locator.length < align) locator += "0";
+                if (locator !== "") while (locator.length < align) locator += "0";
                 return locator;
                 return locator;
             }
             }
 
 
@@ -947,9 +947,10 @@
                     var tst = tests[ndx];
                     var tst = tests[ndx];
                     tstLocator = getLocator(tst, targetLocator.length);
                     tstLocator = getLocator(tst, targetLocator.length);
                     var distance = Math.abs(tstLocator - targetLocator);
                     var distance = Math.abs(tstLocator - targetLocator);
-                    if (tst.match.optionality)
-                        distance += (tests.length - ndx);
-                    if (closest === undefined || (tstLocator !== "" && distance < closest)) {
+                    if (closest === undefined
+                        || (tstLocator !== "" && distance < closest)
+                        || (bestMatch && bestMatch.match.optionality && (!tst.match.optionality || !tst.match.newBlockMarker))
+                        || (bestMatch && bestMatch.match.optionalQuantifier && !tst.match.optionalQuantifier)) {
                         closest = distance;
                         closest = distance;
                         bestMatch = tst;
                         bestMatch = tst;
                     }
                     }
@@ -1100,6 +1101,10 @@
                                 var optionalToken = match;
                                 var optionalToken = match;
                                 match = resolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse);
                                 match = resolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse);
                                 if (match) {
                                 if (match) {
+                                    //mark optionality in matches
+                                    $.each(matches, function (ndx, mtch) {
+                                        mtch.match.optionality = true;
+                                    });
                                     latestMatch = matches[matches.length - 1].match;
                                     latestMatch = matches[matches.length - 1].match;
                                     if (quantifierRecurse === undefined && isFirstMatch(latestMatch, optionalToken)) { //prevent loop see #698
                                     if (quantifierRecurse === undefined && isFirstMatch(latestMatch, optionalToken)) { //prevent loop see #698
                                         insertStop = true; //insert a stop
                                         insertStop = true; //insert a stop
@@ -1301,7 +1306,7 @@
                     matches.push({
                     matches.push({
                         match: {
                         match: {
                             fn: null,
                             fn: null,
-                            optionality: true,
+                            optionality: false,
                             casing: null,
                             casing: null,
                             def: "",
                             def: "",
                             placeholder: ""
                             placeholder: ""