浏览代码

#215 fix numerics for autogroup and leading zeros

Robin Herbots 11 年之前
父节点
当前提交
b4e5044d24

+ 1 - 1
bower.json

@@ -1,6 +1,6 @@
 {
     "name": "jquery.inputmask",
-    "version": "3.0.35",
+    "version": "3.0.36",
     "main": "./dist/jquery.inputmask.bundle.js",
 	"keywords" : ["jQuery", "plugins", "input", "form", "inputmask", "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.minor = 0
-build.revision = 35
+build.revision = 36
 
 target = jquery.inputmask.bundle.js
 target.min = jquery.inputmask.bundle.min.js

二进制
dist/jQuery.InputMask.3.0.35.nupkg


二进制
dist/jQuery.InputMask.3.0.36.nupkg


+ 19 - 15
dist/jquery.inputmask.bundle.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2014 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.0.35
+* Version: 3.0.36
 */
 
 (function ($) {
@@ -523,7 +523,7 @@
             function refreshFromBuffer(start, end) {
                 var buffer = getBuffer().slice(); //work on clone
                 for (var i = start; i < end; i++) {
-                    if (buffer[i] != getPlaceholder(i) && buffer[i] != opts.skipOptionalPartCharacter) {
+                    if (buffer[i] != opts.skipOptionalPartCharacter) {
                         isValid(i, buffer[i], true, true);
                     }
                 }
@@ -587,7 +587,7 @@
                                 }
                                 validatedPos = rslt.pos != undefined ? rslt.pos : position;
                                 if (validatedPos != position) {
-                                    rslt = isValid(validatedPos, elem, true, true); //revalidate new position strict
+                                    rslt = isValid(validatedPos, elem, true); //revalidate new position strict
                                     return false;
                                 }
 
@@ -595,7 +595,7 @@
                                 validatedPos = rslt["pos"];
                                 refreshFromBuffer(position, validatedPos);
                                 if (validatedPos != position) {
-                                    rslt = isValid(validatedPos, elem, true, true); //revalidate new position strict
+                                    rslt = isValid(validatedPos, elem, true); //revalidate new position strict
                                     return false;
                                 }
                             }
@@ -1655,7 +1655,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2014 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.0.35
+* Version: 3.0.36
 */
 
 (function ($) {
@@ -2020,7 +2020,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.35
+Version: 3.0.36
 
 Optional extensions on the jquery.inputmask base
 */
@@ -2141,7 +2141,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.35
+Version: 3.0.36
 
 Optional extensions on the jquery.inputmask base
 */
@@ -2604,7 +2604,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.35
+Version: 3.0.36
 
 Optional extensions on the jquery.inputmask base
 */
@@ -2669,7 +2669,7 @@ Optional extensions on the jquery.inputmask base
             rightAlign: true,
             postFormat: function (buffer, pos, reformatOnly, opts) {
                 var needsRefresh = false;
-                if (opts.groupSeparator == "") return { pos: pos };
+                if (opts.groupSeparator == "" || ($.inArray(opts.radixPoint, buffer) != -1 && pos >= $.inArray(opts.radixPoint, buffer))) return { pos: pos };
                 var cbuf = buffer.slice();
                 if (!reformatOnly) {
                     cbuf.splice(pos, 0, "?"); //set position indicator
@@ -2736,10 +2736,11 @@ Optional extensions on the jquery.inputmask base
 
                             //handle 0 for integerpart
                             if (isValid != false) {
-                                var matchRslt = buffer.join('').match(opts.regex.integerPart(opts));
-                                if (matchRslt && matchRslt["0"][0] == 0 && pos > opts.prefix.length && ($.inArray(opts.radixPoint, buffer) == -1 || pos < $.inArray(opts.radixPoint, buffer))) {
+                                var matchRslt = buffer.join('').match(opts.regex.integerPart(opts)), radixPosition = $.inArray(opts.radixPoint, buffer);
+                                if (matchRslt && matchRslt["0"][0] == "0" && pos >= opts.prefix.length && (radixPosition == -1 || pos < radixPosition)) {
                                     buffer.splice(matchRslt.index, 1);
-                                    return { "pos": matchRslt.index, "c": chrs, "refreshFromBuffer": true, "caret": pos };
+                                } else if (chrs == "0" && matchRslt && matchRslt["0"].length > 0 && pos == opts.prefix.length) {
+                                    return false;
                                 }
                             }
                             if (isValid != false && !strict && chrs != opts.radixPoint && opts.autoGroup === true) {
@@ -2765,7 +2766,10 @@ Optional extensions on the jquery.inputmask base
                 }
             },
             insertMode: true,
-            autoUnmask: false
+            autoUnmask: false,
+            onUnMask: function (maskedValue, unmaskedValue, opts) {
+                return unmaskedValue;
+            }
         },
         'decimal': {
             alias: "numeric"
@@ -2781,7 +2785,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.35
+Version: 3.0.36
 
 Regex extensions on the jquery.inputmask base
 Allows for using regular expressions as a mask
@@ -2968,7 +2972,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.35
+Version: 3.0.36
 
 Phone extension.
 When using this extension make sure you specify the correct url to get the masks

文件差异内容过多而无法显示
+ 84 - 83
dist/jquery.inputmask.bundle.min.js


文件差异内容过多而无法显示
+ 1 - 1
dist/min/jquery.inputmask-multi.js


文件差异内容过多而无法显示
+ 48 - 48
dist/min/jquery.inputmask.js


文件差异内容过多而无法显示
+ 6 - 5
dist/min/jquery.inputmask.numeric.extensions.js


+ 1 - 1
jquery.inputmask.jquery.json

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

+ 3 - 3
js/jquery.inputmask.js

@@ -523,7 +523,7 @@
             function refreshFromBuffer(start, end) {
                 var buffer = getBuffer().slice(); //work on clone
                 for (var i = start; i < end; i++) {
-                    if (buffer[i] != getPlaceholder(i) && buffer[i] != opts.skipOptionalPartCharacter) {
+                    if (buffer[i] != opts.skipOptionalPartCharacter) {
                         isValid(i, buffer[i], true, true);
                     }
                 }
@@ -587,7 +587,7 @@
                                 }
                                 validatedPos = rslt.pos != undefined ? rslt.pos : position;
                                 if (validatedPos != position) {
-                                    rslt = isValid(validatedPos, elem, true, true); //revalidate new position strict
+                                    rslt = isValid(validatedPos, elem, true); //revalidate new position strict
                                     return false;
                                 }
 
@@ -595,7 +595,7 @@
                                 validatedPos = rslt["pos"];
                                 refreshFromBuffer(position, validatedPos);
                                 if (validatedPos != position) {
-                                    rslt = isValid(validatedPos, elem, true, true); //revalidate new position strict
+                                    rslt = isValid(validatedPos, elem, true); //revalidate new position strict
                                     return false;
                                 }
                             }

+ 9 - 5
js/jquery.inputmask.numeric.extensions.js

@@ -68,7 +68,7 @@ Optional extensions on the jquery.inputmask base
             rightAlign: true,
             postFormat: function (buffer, pos, reformatOnly, opts) {
                 var needsRefresh = false;
-                if (opts.groupSeparator == "") return { pos: pos };
+                if (opts.groupSeparator == "" || ($.inArray(opts.radixPoint, buffer) != -1 && pos >= $.inArray(opts.radixPoint, buffer))) return { pos: pos };
                 var cbuf = buffer.slice();
                 if (!reformatOnly) {
                     cbuf.splice(pos, 0, "?"); //set position indicator
@@ -135,10 +135,11 @@ Optional extensions on the jquery.inputmask base
 
                             //handle 0 for integerpart
                             if (isValid != false) {
-                                var matchRslt = buffer.join('').match(opts.regex.integerPart(opts));
-                                if (matchRslt && matchRslt["0"][0] == 0 && pos > opts.prefix.length && ($.inArray(opts.radixPoint, buffer) == -1 || pos < $.inArray(opts.radixPoint, buffer))) {
+                                var matchRslt = buffer.join('').match(opts.regex.integerPart(opts)), radixPosition = $.inArray(opts.radixPoint, buffer);
+                                if (matchRslt && matchRslt["0"][0] == "0" && pos >= opts.prefix.length && (radixPosition == -1 || pos < radixPosition)) {
                                     buffer.splice(matchRslt.index, 1);
-                                    return { "pos": matchRslt.index, "c": chrs, "refreshFromBuffer": true, "caret": pos };
+                                } else if (chrs == "0" && matchRslt && matchRslt["0"].length > 0 && pos == opts.prefix.length) {
+                                    return false;
                                 }
                             }
                             if (isValid != false && !strict && chrs != opts.radixPoint && opts.autoGroup === true) {
@@ -164,7 +165,10 @@ Optional extensions on the jquery.inputmask base
                 }
             },
             insertMode: true,
-            autoUnmask: false
+            autoUnmask: false,
+            onUnMask: function (maskedValue, unmaskedValue, opts) {
+                return unmaskedValue;
+            }
         },
         'decimal': {
             alias: "numeric"

+ 140 - 0
qunit/tests_numeric.js

@@ -1,5 +1,145 @@
 module("Numeric.Extensions");
 
+test("integer  type 124 correct to 1234", function () {
+    var $fixture = $("#qunit-fixture");
+    $fixture.append('<input type="text" id="testmask" />');
+    $("#testmask").inputmask("numeric", {
+        groupSeparator: ",",
+        autoGroup: true
+    });
+
+    $("#testmask")[0].focus();
+    $("#testmask").Type("124");
+    caret($("#testmask")[0], 2);
+    $("#testmask").Type("3");
+    equal($("#testmask").val(), "1,234", "Result " + $("#testmask").val());
+    $("#testmask").remove();
+});
+
+test("numeric  type 00000 - Webunity", function () {
+    var $fixture = $("#qunit-fixture");
+    $fixture.append('<input type="text" id="testmask" />');
+    $("#testmask").inputmask("numeric", {
+        groupSeparator: ",",
+        autoGroup: true,
+        integerDigits: 9
+    });
+
+    $("#testmask")[0].focus();
+    $("#testmask").Type("00000");
+
+    equal($("#testmask").val(), "0", "Result " + $("#testmask").val());
+    $("#testmask").remove();
+});
+
+test("numeric -placeholder 0 type 00000 - Webunity", function () {
+    var $fixture = $("#qunit-fixture");
+    $fixture.append('<input type="text" id="testmask" />');
+    $("#testmask").inputmask("numeric", {
+        groupSeparator: ",",
+        autoGroup: true,
+        placeholder: "0"
+    });
+
+    $("#testmask")[0].focus();
+    $("#testmask").Type("00000");
+
+    equal($("#testmask").val(), "0", "Result " + $("#testmask").val());
+    $("#testmask").remove();
+});
+
+test("numeric placeholder 0 prefix € type 0.123 - Webunity", function () {
+    var $fixture = $("#qunit-fixture");
+    $fixture.append('<input type="text" id="testmask" />');
+    $("#testmask").inputmask("numeric", {
+        groupSeparator: ",",
+        autoGroup: true,
+        placeholder: "0",
+        prefix: "€ "
+    });
+
+    $("#testmask")[0].focus();
+    $("#testmask").Type("0.123");
+
+    equal($("#testmask").val(), "€ 0.123", "Result " + $("#testmask").val());
+    $("#testmask").remove();
+});
+
+test("numeric placeholder 0 prefix € type 0.123 - backspace - Webunity", function () {
+    var $fixture = $("#qunit-fixture");
+    $fixture.append('<input type="text" id="testmask" />');
+    $("#testmask").inputmask("numeric", {
+        groupSeparator: ",",
+        autoGroup: true,
+        placeholder: "0",
+        prefix: "€ "
+    });
+
+    $("#testmask")[0].focus();
+    $("#testmask").Type("0.123");
+    $("#testmask").SendKey(keyCodes.BACKSPACE);
+
+    equal($("#testmask").val(), "€ 0.12", "Result " + $("#testmask").val());
+    $("#testmask").remove();
+});
+
+test("numeric placeholder 0 prefix € type 0.123 + add 1 in front - Webunity", function () {
+    var $fixture = $("#qunit-fixture");
+    $fixture.append('<input type="text" id="testmask" />');
+    $("#testmask").inputmask("numeric", {
+        groupSeparator: ",",
+        autoGroup: true,
+        placeholder: "0",
+        prefix: "€ "
+    });
+
+    $("#testmask")[0].focus();
+    $("#testmask").Type("0.123");
+    caret($("#testmask")[0], 2);
+    $("#testmask").Type("1");
+
+    equal($("#testmask").val(), "€ 10.123", "Result " + $("#testmask").val());
+    $("#testmask").remove();
+});
+
+test("numeric placeholder 0 autoGroup: false prefix € type 0.123 + add 123 in front - Webunity", function () {
+    var $fixture = $("#qunit-fixture");
+    $fixture.append('<input type="text" id="testmask" />');
+    $("#testmask").inputmask("numeric", {
+        groupSeparator: ",",
+        autoGroup: false,
+        placeholder: "0",
+        prefix: "€ "
+    });
+
+    $("#testmask")[0].focus();
+    $("#testmask").Type("0.123");
+    caret($("#testmask")[0], 2);
+    $("#testmask").Type("123");
+
+    equal($("#testmask").val(), "€ 1230.123", "Result " + $("#testmask").val());
+    $("#testmask").remove();
+});
+
+test("numeric placeholder 0 autoGroup: true prefix € type 0.123 + add 123 in front - Webunity", function () {
+    var $fixture = $("#qunit-fixture");
+    $fixture.append('<input type="text" id="testmask" />');
+    $("#testmask").inputmask("numeric", {
+        groupSeparator: ",",
+        autoGroup: true,
+        placeholder: "0",
+        prefix: "€ "
+    });
+
+    $("#testmask")[0].focus();
+    $("#testmask").Type("0.123");
+    caret($("#testmask")[0], 2);
+    $("#testmask").Type("123");
+
+    equal($("#testmask").val(), "€ 1,230.123", "Result " + $("#testmask").val());
+    $("#testmask").remove();
+});
+
 test("integer alias with integerDigits 9 & autogroup - type 123456789 - gigermocas", function () {
     var $fixture = $("#qunit-fixture");
     $fixture.append('<input type="text" id="testmask" />');