Browse Source

fix for isComplete + qunit tests

Robin Herbots 11 years ago
parent
commit
a55839af77

+ 8 - 6
dist/inputmask/jquery.inputmask.js

@@ -561,12 +561,11 @@
                 }
                 return isMatch;
             }
-            var inputValue = void 0 != nptvl ? nptvl.slice() : input._valueGet().split("");
+            var inputValue = void 0 != nptvl ? nptvl.slice() : input._valueGet().split(""), charCodes = "", initialNdx = 0;
             resetMaskSet(), getMaskSet().p = seekNext(-1), writeOut && input._valueSet("");
             var staticInput = getBufferTemplate().slice(0, seekNext(-1)).join(""), matches = inputValue.join("").match(new RegExp(escapeRegex(staticInput), "g"));
-            matches && matches.length > 0 && inputValue.splice(0, staticInput.length * matches.length);
-            var charCodes = "", initialNdx = 0;
-            $.each(inputValue, function(ndx, charCode) {
+            matches && matches.length > 0 && (inputValue.splice(0, matches.length * staticInput.length), 
+            initialNdx = seekNext(initialNdx)), $.each(inputValue, function(ndx, charCode) {
                 var keypress = $.Event("keypress");
                 keypress.which = charCode.charCodeAt(0), charCodes += charCode;
                 var lvp = getLastValidPosition(), lvTest = getMaskSet().validPositions[lvp], nextTest = getTestTemplate(lvp + 1, lvTest ? lvTest.locator.slice() : void 0, lvp);
@@ -633,8 +632,11 @@
         function isComplete(buffer) {
             if ($.isFunction(opts.isComplete)) return opts.isComplete.call($el, buffer, opts);
             if ("*" == opts.repeat) return void 0;
-            var complete = !1, lrp = determineLastRequiredPosition(!0), aml = seekPrevious(lrp.l), lvp = getLastValidPosition();
-            if (lvp == aml && (void 0 == lrp.def || lrp.def.newBlockMarker || lrp.def.optionalQuantifier)) {
+            {
+                var complete = !1, lrp = determineLastRequiredPosition(!0), aml = seekPrevious(lrp.l);
+                getLastValidPosition();
+            }
+            if (void 0 == lrp.def || lrp.def.newBlockMarker || lrp.def.optionalQuantifier) {
                 complete = !0;
                 for (var i = 0; aml >= i; i++) {
                     var mask = isMask(i);

File diff suppressed because it is too large
+ 1 - 1
dist/inputmask/jquery.inputmask.min.js


+ 8 - 6
dist/jquery.inputmask.bundle.js

@@ -559,12 +559,11 @@
                 }
                 return isMatch;
             }
-            var inputValue = void 0 != nptvl ? nptvl.slice() : input._valueGet().split("");
+            var inputValue = void 0 != nptvl ? nptvl.slice() : input._valueGet().split(""), charCodes = "", initialNdx = 0;
             resetMaskSet(), getMaskSet().p = seekNext(-1), writeOut && input._valueSet("");
             var staticInput = getBufferTemplate().slice(0, seekNext(-1)).join(""), matches = inputValue.join("").match(new RegExp(escapeRegex(staticInput), "g"));
-            matches && matches.length > 0 && inputValue.splice(0, staticInput.length * matches.length);
-            var charCodes = "", initialNdx = 0;
-            $.each(inputValue, function(ndx, charCode) {
+            matches && matches.length > 0 && (inputValue.splice(0, matches.length * staticInput.length), 
+            initialNdx = seekNext(initialNdx)), $.each(inputValue, function(ndx, charCode) {
                 var keypress = $.Event("keypress");
                 keypress.which = charCode.charCodeAt(0), charCodes += charCode;
                 var lvp = getLastValidPosition(), lvTest = getMaskSet().validPositions[lvp], nextTest = getTestTemplate(lvp + 1, lvTest ? lvTest.locator.slice() : void 0, lvp);
@@ -631,8 +630,11 @@
         function isComplete(buffer) {
             if ($.isFunction(opts.isComplete)) return opts.isComplete.call($el, buffer, opts);
             if ("*" == opts.repeat) return void 0;
-            var complete = !1, lrp = determineLastRequiredPosition(!0), aml = seekPrevious(lrp.l), lvp = getLastValidPosition();
-            if (lvp == aml && (void 0 == lrp.def || lrp.def.newBlockMarker || lrp.def.optionalQuantifier)) {
+            {
+                var complete = !1, lrp = determineLastRequiredPosition(!0), aml = seekPrevious(lrp.l);
+                getLastValidPosition();
+            }
+            if (void 0 == lrp.def || lrp.def.newBlockMarker || lrp.def.optionalQuantifier) {
                 complete = !0;
                 for (var i = 0; aml >= i; i++) {
                     var mask = isMask(i);

File diff suppressed because it is too large
+ 1 - 1
dist/jquery.inputmask.bundle.min.js


+ 11 - 12
js/jquery.inputmask.js

@@ -1010,17 +1010,18 @@
 
                     return isMatch;
                 }
-                var inputValue = nptvl != undefined ? nptvl.slice() : input._valueGet().split('');
+                var inputValue = nptvl != undefined ? nptvl.slice() : input._valueGet().split(''), charCodes = "", initialNdx = 0;
                 resetMaskSet();
                 getMaskSet()["p"] = seekNext(-1);
                 if (writeOut) input._valueSet(""); //initial clear
 
                 var staticInput = getBufferTemplate().slice(0, seekNext(-1)).join(''), matches = inputValue.join('').match(new RegExp(escapeRegex(staticInput), "g"));
                 if (matches && matches.length > 0) {
-                    inputValue.splice(0, staticInput.length * matches.length);
+                    inputValue.splice(0, matches.length * staticInput.length);
+                    initialNdx = seekNext(initialNdx);
                 }
 
-                var charCodes = "", initialNdx = 0;
+
                 $.each(inputValue, function (ndx, charCode) {
                     var keypress = $.Event("keypress");
                     keypress.which = charCode.charCodeAt(0);
@@ -1136,15 +1137,13 @@
                 if (opts.repeat == "*") return undefined;
                 var complete = false, lrp = determineLastRequiredPosition(true), aml = seekPrevious(lrp["l"]), lvp = getLastValidPosition();
 
-                if (lvp == aml) {
-                    if (lrp["def"] == undefined || lrp["def"].newBlockMarker || lrp["def"].optionalQuantifier) {
-                        complete = true;
-                        for (var i = 0; i <= aml; i++) {
-                            var mask = isMask(i);
-                            if ((mask && (buffer[i] == undefined || buffer[i] == getPlaceholder(i))) || (!mask && buffer[i] != getPlaceholder(i))) {
-                                complete = false;
-                                break;
-                            }
+                if (lrp["def"] == undefined || lrp["def"].newBlockMarker || lrp["def"].optionalQuantifier) {
+                    complete = true;
+                    for (var i = 0; i <= aml; i++) {
+                        var mask = isMask(i);
+                        if ((mask && (buffer[i] == undefined || buffer[i] == getPlaceholder(i))) || (!mask && buffer[i] != getPlaceholder(i))) {
+                            complete = false;
+                            break;
                         }
                     }
                 }

+ 21 - 1
qunit/tests_formatvalidate.js

@@ -117,4 +117,24 @@ test("YoussefTaghlabi isValid(\"12,345.67\", { alias: \"decimal\" }", function (
         groupSize: 3
     });
     equal(isValid, true, "Result " + isValid);
-});
+});
+
+test("thomstark isValid(\"12lbs\", {mask:\"99[9]lb\\s\", greedy:false, skipOptionalPartCharacter: \"\", \"clearIncomplete\":true}", function () {
+    var isValid = $.inputmask.isValid("12lbs", {mask:"99[9]lb\\s", greedy:false, skipOptionalPartCharacter: "", "clearIncomplete":true});
+    equal(isValid, true, "Result " + isValid);
+});
+
+test("thomstark isValid(\"1'2\"\", {mask:\"9'9[9]\"\", greedy:false, skipOptionalPartCharacter: \"\", \"clearIncomplete\":true}", function () {
+    var isValid = $.inputmask.isValid("1'2\"", {mask:"9'9[9]\"", greedy:false, skipOptionalPartCharacter: "", "clearIncomplete":true});
+    equal(isValid, true, "Result " + isValid);
+});
+
+test("thomstark isValid(\"12lbs\", {mask:\"99{1,2}lb\\s\", greedy:false, skipOptionalPartCharacter: \"\", \"clearIncomplete\":true}", function () {
+    var isValid = $.inputmask.isValid("12lbs", { mask: "99{1,2}lb\\s", greedy: false, skipOptionalPartCharacter: "", "clearIncomplete": true });
+    equal(isValid, true, "Result " + isValid);
+});
+
+test("thomstark isValid(\"9'9{1,2}\", {mask:\"9'9[9]\"\", greedy:false, skipOptionalPartCharacter: \"\", \"clearIncomplete\":true}", function () {
+    var isValid = $.inputmask.isValid("1'2\"", { mask: "9'9{1,2}\"", greedy: false, skipOptionalPartCharacter: "", "clearIncomplete": true });
+    equal(isValid, true, "Result " + isValid);
+});

+ 14 - 0
qunit/tests_paste.js

@@ -233,4 +233,18 @@ asyncTest("currency ~ 000.02 - sjk07", function () {
         start();
         $("#testmask").remove();
     }, 0);
+});
+
+asyncTest("02.999.999 ~ paste 02.024.900 - tnavarra", function () {
+    var $fixture = $("#qunit-fixture");
+    $fixture.append('<input type="text" id="testmask" />');
+    $("#testmask").inputmask("02.999.999");
+    $("#testmask")[0].focus();
+    $("#testmask").paste("02.024.900");
+
+    setTimeout(function () {
+        equal($("#testmask").val(), "02.024.900", "Result " + $("#testmask").val());
+        start();
+        $("#testmask").remove();
+    }, 0);
 });