Browse Source

fix iscomplete

Robin Herbots 11 years ago
parent
commit
80cd7468c4

+ 1 - 1
bower.json

@@ -1,6 +1,6 @@
 {
 {
     "name": "jquery.inputmask",
     "name": "jquery.inputmask",
-    "version": "3.0.36",
+    "version": "3.0.37",
     "main": "./dist/jquery.inputmask.bundle.js",
     "main": "./dist/jquery.inputmask.bundle.js",
 	"keywords" : ["jQuery", "plugins", "input", "form", "inputmask", "mask"],
 	"keywords" : ["jQuery", "plugins", "input", "form", "inputmask", "mask"],
 	"description": "jquery.inputmask is a jquery plugin which create an input mask.",
 	"description": "jquery.inputmask is a jquery plugin which create an input mask.",

+ 1 - 1
build.properties

@@ -7,7 +7,7 @@ distdir = dist
 
 
 build.major = 3
 build.major = 3
 build.minor = 0
 build.minor = 0
-build.revision = 36
+build.revision = 37
 
 
 target = jquery.inputmask.bundle.js
 target = jquery.inputmask.bundle.js
 target.min = jquery.inputmask.bundle.min.js
 target.min = jquery.inputmask.bundle.min.js

BIN
dist/jQuery.InputMask.3.0.36.nupkg


BIN
dist/jQuery.InputMask.3.0.37.nupkg


+ 41 - 38
dist/jquery.inputmask.bundle.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2014 Robin Herbots
 * Copyright (c) 2010 - 2014 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.0.36
+* Version: 3.0.37
 */
 */
 
 
 (function ($) {
 (function ($) {
@@ -718,26 +718,6 @@
             function truncateInput(inputValue) {
             function truncateInput(inputValue) {
                 return inputValue.replace(new RegExp("(" + escapeRegex(getBufferTemplate().join('')) + ")*$"), "");
                 return inputValue.replace(new RegExp("(" + escapeRegex(getBufferTemplate().join('')) + ")*$"), "");
             }
             }
-
-            function clearOptionalTail(input) {
-                var buffer = getBuffer(), tmpBuffer = buffer.slice(),
-                    pos, lvp = getLastValidPosition(), positions = {},
-                    ndxIntlzr = getMaskSet()["validPositions"][lvp] != undefined ? getMaskSet()["validPositions"][lvp]["locator"].slice() : undefined, testPos;
-                for (pos = lvp + 1; pos < tmpBuffer.length; pos++) {
-                    testPos = getTestTemplate(pos, ndxIntlzr, pos - 1);
-                    ndxIntlzr = testPos["locator"].slice();
-                    positions[pos] = testPos;
-                }
-
-                for (pos = tmpBuffer.length - 1; pos > lvp; pos--) {
-                    testPos = positions[pos]["match"];
-                    if (testPos.optionality && tmpBuffer[pos] == getPlaceholder(pos, testPos)) {
-                        tmpBuffer.pop();
-                    } else break;
-                }
-                writeBuffer(input, tmpBuffer);
-            }
-
             function unmaskedvalue($input, skipDatepickerCheck) {
             function unmaskedvalue($input, skipDatepickerCheck) {
                 if ($input.data('_inputmask') && (skipDatepickerCheck === true || !$input.hasClass('hasDatepicker'))) {
                 if ($input.data('_inputmask') && (skipDatepickerCheck === true || !$input.hasClass('hasDatepicker'))) {
                     var umValue = [], vps = getMaskSet()["validPositions"];
                     var umValue = [], vps = getMaskSet()["validPositions"];
@@ -753,7 +733,6 @@
                     return $input[0]._valueGet();
                     return $input[0]._valueGet();
                 }
                 }
             }
             }
-
             function TranslatePosition(pos) {
             function TranslatePosition(pos) {
                 if (isRTL && typeof pos == 'number' && (!opts.greedy || opts.placeholder != "")) {
                 if (isRTL && typeof pos == 'number' && (!opts.greedy || opts.placeholder != "")) {
                     var bffrLght = getBuffer().length;
                     var bffrLght = getBuffer().length;
@@ -761,7 +740,6 @@
                 }
                 }
                 return pos;
                 return pos;
             }
             }
-
             function caret(input, begin, end) {
             function caret(input, begin, end) {
                 var npt = input.jquery && input.length > 0 ? input[0] : input, range;
                 var npt = input.jquery && input.length > 0 ? input[0] : input, range;
                 if (typeof begin == 'number') {
                 if (typeof begin == 'number') {
@@ -809,19 +787,44 @@
                     return { "begin": begin, "end": end };
                     return { "begin": begin, "end": end };
                 }
                 }
             }
             }
+            function determineLastRequiredPosition(returnDefinition) {
+                var buffer = getBuffer(), bl = buffer.length,
+                   pos, lvp = getLastValidPosition(), positions = {},
+                   ndxIntlzr = getMaskSet()["validPositions"][lvp] != undefined ? getMaskSet()["validPositions"][lvp]["locator"].slice() : undefined, testPos;
+                for (pos = lvp + 1; pos < buffer.length; pos++) {
+                    testPos = getTestTemplate(pos, ndxIntlzr, pos - 1);
+                    ndxIntlzr = testPos["locator"].slice();
+                    positions[pos] = $.extend(true, {}, testPos);
+                }
 
 
+                for (pos = bl - 1; pos > lvp; pos--) {
+                    testPos = positions[pos]["match"];
+                    if ((testPos.optionality || testPos.optionalQuantifier) && buffer[pos] == getPlaceholder(pos, testPos)) {
+                        bl--;
+                    } else break;
+                }
+                return returnDefinition ? { "l": bl, "def": positions[bl] ? positions[bl]["match"] : undefined } : bl;
+            }
+            function clearOptionalTail(input) {
+                var buffer = getBuffer(), tmpBuffer = buffer.slice();
+                var rl = determineLastRequiredPosition();
+                tmpBuffer.length = rl;
+                writeBuffer(input, tmpBuffer);
+            }
             function isComplete(buffer) { //return true / false / undefined (repeat *)
             function isComplete(buffer) { //return true / false / undefined (repeat *)
                 if ($.isFunction(opts.isComplete)) return opts.isComplete.call($el, buffer, opts);
                 if ($.isFunction(opts.isComplete)) return opts.isComplete.call($el, buffer, opts);
                 if (opts.repeat == "*") return undefined;
                 if (opts.repeat == "*") return undefined;
-                var complete = false,
-                    aml = seekPrevious(getMaskLength());
-                if (getLastValidPosition() == aml) {
-                    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;
+                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;
+                            }
                         }
                         }
                     }
                     }
                 }
                 }
@@ -1655,7 +1658,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2014 Robin Herbots
 * Copyright (c) 2010 - 2014 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.0.36
+* Version: 3.0.37
 */
 */
 
 
 (function ($) {
 (function ($) {
@@ -2020,7 +2023,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.36
+Version: 3.0.37
 
 
 Optional extensions on the jquery.inputmask base
 Optional extensions on the jquery.inputmask base
 */
 */
@@ -2141,7 +2144,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.36
+Version: 3.0.37
 
 
 Optional extensions on the jquery.inputmask base
 Optional extensions on the jquery.inputmask base
 */
 */
@@ -2604,7 +2607,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.36
+Version: 3.0.37
 
 
 Optional extensions on the jquery.inputmask base
 Optional extensions on the jquery.inputmask base
 */
 */
@@ -2785,7 +2788,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.36
+Version: 3.0.37
 
 
 Regex extensions on the jquery.inputmask base
 Regex extensions on the jquery.inputmask base
 Allows for using regular expressions as a mask
 Allows for using regular expressions as a mask
@@ -2972,7 +2975,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.36
+Version: 3.0.37
 
 
 Phone extension.
 Phone extension.
 When using this extension make sure you specify the correct url to get the masks
 When using this extension make sure you specify the correct url to get the masks

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


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


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


+ 1 - 1
jquery.inputmask.jquery.json

@@ -8,7 +8,7 @@
 		"inputmask",
 		"inputmask",
 		"mask"
 		"mask"
     ],
     ],
-    "version": "3.0.36",
+    "version": "3.0.37",
     "author": {
     "author": {
         "name": "Robin Herbots",
         "name": "Robin Herbots",
         "url": "http://github.com/RobinHerbots/jquery.inputmask"
         "url": "http://github.com/RobinHerbots/jquery.inputmask"

+ 34 - 31
js/jquery.inputmask.js

@@ -718,26 +718,6 @@
             function truncateInput(inputValue) {
             function truncateInput(inputValue) {
                 return inputValue.replace(new RegExp("(" + escapeRegex(getBufferTemplate().join('')) + ")*$"), "");
                 return inputValue.replace(new RegExp("(" + escapeRegex(getBufferTemplate().join('')) + ")*$"), "");
             }
             }
-
-            function clearOptionalTail(input) {
-                var buffer = getBuffer(), tmpBuffer = buffer.slice(),
-                    pos, lvp = getLastValidPosition(), positions = {},
-                    ndxIntlzr = getMaskSet()["validPositions"][lvp] != undefined ? getMaskSet()["validPositions"][lvp]["locator"].slice() : undefined, testPos;
-                for (pos = lvp + 1; pos < tmpBuffer.length; pos++) {
-                    testPos = getTestTemplate(pos, ndxIntlzr, pos - 1);
-                    ndxIntlzr = testPos["locator"].slice();
-                    positions[pos] = testPos;
-                }
-
-                for (pos = tmpBuffer.length - 1; pos > lvp; pos--) {
-                    testPos = positions[pos]["match"];
-                    if (testPos.optionality && tmpBuffer[pos] == getPlaceholder(pos, testPos)) {
-                        tmpBuffer.pop();
-                    } else break;
-                }
-                writeBuffer(input, tmpBuffer);
-            }
-
             function unmaskedvalue($input, skipDatepickerCheck) {
             function unmaskedvalue($input, skipDatepickerCheck) {
                 if ($input.data('_inputmask') && (skipDatepickerCheck === true || !$input.hasClass('hasDatepicker'))) {
                 if ($input.data('_inputmask') && (skipDatepickerCheck === true || !$input.hasClass('hasDatepicker'))) {
                     var umValue = [], vps = getMaskSet()["validPositions"];
                     var umValue = [], vps = getMaskSet()["validPositions"];
@@ -753,7 +733,6 @@
                     return $input[0]._valueGet();
                     return $input[0]._valueGet();
                 }
                 }
             }
             }
-
             function TranslatePosition(pos) {
             function TranslatePosition(pos) {
                 if (isRTL && typeof pos == 'number' && (!opts.greedy || opts.placeholder != "")) {
                 if (isRTL && typeof pos == 'number' && (!opts.greedy || opts.placeholder != "")) {
                     var bffrLght = getBuffer().length;
                     var bffrLght = getBuffer().length;
@@ -761,7 +740,6 @@
                 }
                 }
                 return pos;
                 return pos;
             }
             }
-
             function caret(input, begin, end) {
             function caret(input, begin, end) {
                 var npt = input.jquery && input.length > 0 ? input[0] : input, range;
                 var npt = input.jquery && input.length > 0 ? input[0] : input, range;
                 if (typeof begin == 'number') {
                 if (typeof begin == 'number') {
@@ -809,19 +787,44 @@
                     return { "begin": begin, "end": end };
                     return { "begin": begin, "end": end };
                 }
                 }
             }
             }
+            function determineLastRequiredPosition(returnDefinition) {
+                var buffer = getBuffer(), bl = buffer.length,
+                   pos, lvp = getLastValidPosition(), positions = {},
+                   ndxIntlzr = getMaskSet()["validPositions"][lvp] != undefined ? getMaskSet()["validPositions"][lvp]["locator"].slice() : undefined, testPos;
+                for (pos = lvp + 1; pos < buffer.length; pos++) {
+                    testPos = getTestTemplate(pos, ndxIntlzr, pos - 1);
+                    ndxIntlzr = testPos["locator"].slice();
+                    positions[pos] = $.extend(true, {}, testPos);
+                }
 
 
+                for (pos = bl - 1; pos > lvp; pos--) {
+                    testPos = positions[pos]["match"];
+                    if ((testPos.optionality || testPos.optionalQuantifier) && buffer[pos] == getPlaceholder(pos, testPos)) {
+                        bl--;
+                    } else break;
+                }
+                return returnDefinition ? { "l": bl, "def": positions[bl] ? positions[bl]["match"] : undefined } : bl;
+            }
+            function clearOptionalTail(input) {
+                var buffer = getBuffer(), tmpBuffer = buffer.slice();
+                var rl = determineLastRequiredPosition();
+                tmpBuffer.length = rl;
+                writeBuffer(input, tmpBuffer);
+            }
             function isComplete(buffer) { //return true / false / undefined (repeat *)
             function isComplete(buffer) { //return true / false / undefined (repeat *)
                 if ($.isFunction(opts.isComplete)) return opts.isComplete.call($el, buffer, opts);
                 if ($.isFunction(opts.isComplete)) return opts.isComplete.call($el, buffer, opts);
                 if (opts.repeat == "*") return undefined;
                 if (opts.repeat == "*") return undefined;
-                var complete = false,
-                    aml = seekPrevious(getMaskLength());
-                if (getLastValidPosition() == aml) {
-                    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;
+                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;
+                            }
                         }
                         }
                     }
                     }
                 }
                 }

+ 1 - 1
qunit/tests_dynamic.js

@@ -67,7 +67,7 @@ test("email mask greedy true", function () {
     $("#testmask")[0].focus();
     $("#testmask")[0].focus();
     $("#testmask").Type("some.body@mail.com");
     $("#testmask").Type("some.body@mail.com");
     $("#testmask").blur();
     $("#testmask").blur();
-    equal($("#testmask").val(), "some.body@mail.com___", "Result " + $("#testmask").val());
+    equal($("#testmask").val(), "some.body@mail.com", "Result " + $("#testmask").val());
 
 
     $("#testmask").remove();
     $("#testmask").remove();
 });
 });

+ 24 - 4
qunit/tests_formatvalidate.js

@@ -16,11 +16,31 @@ test("$.inputmask.format(\"12\", {  mask: \"$ 999999\", numericInput: true, plac
 
 
 module("Value Validating");
 module("Value Validating");
 test("$.inputmask.isValid(\"23/03/1973\", { alias: \"date\"})", function () {
 test("$.inputmask.isValid(\"23/03/1973\", { alias: \"date\"})", function () {
-    var formattedValue = $.inputmask.isValid("23/03/1973", { alias: "date" });
-    equal(formattedValue, true, "Result " + formattedValue);
+    var isValid = $.inputmask.isValid("23/03/1973", { alias: "date" });
+    equal(isValid, true, "Result " + isValid);
 });
 });
 
 
 test("$.inputmask.isValid(\"01 650 103 002 0001 DE101 5170\", { mask: \"99 999 999 999 9999 \\D\\E*** 9999\"})", function () {
 test("$.inputmask.isValid(\"01 650 103 002 0001 DE101 5170\", { mask: \"99 999 999 999 9999 \\D\\E*** 9999\"})", function () {
-    var formattedValue = $.inputmask.isValid("01 650 103 002 0001 DE101 5170", { mask: "99 999 999 999 9999 \\D\\E*** 9999" });
-    equal(formattedValue, true, "Result " + formattedValue);
+    var isValid = $.inputmask.isValid("01 650 103 002 0001 DE101 5170", { mask: "99 999 999 999 9999 \\D\\E*** 9999" });
+    equal(isValid, true, "Result " + isValid);
+});
+
+test("$.inputmask.isValid email => false", function () {
+    var isValid = $.inputmask.isValid("some.body@mail.c", { alias: "email" });
+    equal(isValid, false, "Result " + isValid);
+});
+
+test("$.inputmask.isValid email => true", function () {
+    var isValid = $.inputmask.isValid("some.body@mail.com", { alias: "email" });
+    equal(isValid, true, "Result " + isValid);
+});
+
+test("$.inputmask.isValid email greedy => false", function () {
+    var isValid = $.inputmask.isValid("some.body@mail.c", { alias: "email", greedy: true });
+    equal(isValid, false, "Result " + isValid);
+});
+
+test("$.inputmask.isValid email greedy => true", function () {
+    var isValid = $.inputmask.isValid("some.body@mail.com", { alias: "email", greedy: true });
+    equal(isValid, true, "Result " + isValid);
 });
 });