Browse Source

Decimal separator conversion fix #919

Robin Herbots 10 years ago
parent
commit
c98b7434bf

+ 2 - 1
CHANGELOG.md

@@ -21,6 +21,7 @@ All notable changes to this project will be documented in this file.
 - Update placeholder handling
 
 ### Fixed
+- Decimal separator conversion #919
 - Entering a period on a blank 'numeric' alias input not allowed #888
 - Typing 1000 becomes 1.00 using groupSeparator="." #959
 - phone-codes.js is missing when installing with bower #937
@@ -33,7 +34,7 @@ All notable changes to this project will be documented in this file.
 - Decimal looses digits #924
 - Firefox: cursor jumps to the right when clicking anywhere on the value #921
 - Numeric inputMask doesn't rounds value #754
-- Chinese / Japanese characters are unable to mask #198
+- <strike>Chinese / Japanese characters are unable to mask #198</strike>
 - Infinite Loop on IE (v11) when using Japanese IME Keyboard #749
 - Delete key not working properly #799
 - Selecting and overwriting text will delete the character to the immediate right #914

+ 1 - 1
bower.json

@@ -1,6 +1,6 @@
 {
   "name": "jquery.inputmask",
-  "version": "3.1.64-99",
+  "version": "3.1.64-100",
   "main": [
     "./dist/inputmask/jquery.inputmask.js",
     "./dist/inputmask/inputmask.js",

+ 1 - 1
component.json

@@ -2,7 +2,7 @@
     "name": "jquery_inputmask",
     "repository": "robinherbots/jquery.inputmask",
     "description": "jquery.inputmask is a jquery plugin which create an input mask.",
-    "version": "3.1.64-99",
+    "version": "3.1.64-100",
     "keywords": [ "jquery", "plugins", "input", "form", "inputmask", "mask" ],
     "main": "./dist/jquery.inputmask.bundle.js",
     "scripts": [

+ 1 - 1
composer.json

@@ -1,7 +1,7 @@
 {
     "name": "robinherbots/jquery.inputmask",
     "description": "jquery.inputmask is a jquery plugin which create an input mask.",
-	"version": "3.1.64-99",
+	"version": "3.1.64-100",
     "type": "library",
     "keywords": ["jquery", "plugins", "input", "form", "inputmask", "mask"],
     "homepage": "http://robinherbots.github.io/jquery.inputmask",

+ 1 - 1
dist/inputmask/inputmask.date.extensions.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.1.64-99
+* Version: 3.1.64-100
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "./inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery"), require("./inputmask")) : factory(jQuery);

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


+ 1 - 1
dist/inputmask/inputmask.extensions.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.1.64-99
+* Version: 3.1.64-100
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "./inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery"), require("./inputmask")) : factory(jQuery);

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


+ 1 - 1
dist/inputmask/inputmask.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.1.64-99
+* Version: 3.1.64-100
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery")) : factory(jQuery);

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


+ 5 - 3
dist/inputmask/inputmask.numeric.extensions.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.1.64-99
+* Version: 3.1.64-100
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "./inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery"), require("./inputmask")) : factory(jQuery);
@@ -176,7 +176,8 @@
                 return !1;
             },
             radixHandler: function(chrs, maskset, pos, strict, opts) {
-                if (!strict && chrs === opts.radixPoint && void 0 != opts.digits && (isNaN(opts.digits) || parseInt(opts.digits) > 0)) {
+                if (!strict && (-1 != $.inArray(chrs, [ ",", "." ]) && (chrs = opts.radixPoint), 
+                chrs === opts.radixPoint && void 0 != opts.digits && (isNaN(opts.digits) || parseInt(opts.digits) > 0))) {
                     var radixPos = $.inArray(opts.radixPoint, maskset.buffer), integerValue = maskset.buffer.join("").match(opts.regex.integerPart(opts));
                     if (-1 != radixPos && maskset.validPositions[radixPos]) return maskset.validPositions[radixPos - 1] ? {
                         caret: radixPos + 1
@@ -187,7 +188,8 @@
                     };
                     if (!integerValue || "0" == integerValue[0] && integerValue.index + 1 != pos) return maskset.buffer[integerValue ? integerValue.index : pos] = "0", 
                     {
-                        pos: (integerValue ? integerValue.index : pos) + 1
+                        pos: (integerValue ? integerValue.index : pos) + 1,
+                        c: opts.radixPoint
                     };
                 }
                 return !1;

File diff suppressed because it is too large
+ 2 - 2
dist/inputmask/inputmask.numeric.extensions.min.js


+ 1 - 1
dist/inputmask/inputmask.phone.extensions.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.1.64-99
+* Version: 3.1.64-100
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "./inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery"), require("./inputmask")) : factory(jQuery);

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


+ 1 - 1
dist/inputmask/inputmask.regex.extensions.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.1.64-99
+* Version: 3.1.64-100
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "./inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery"), require("./inputmask")) : factory(jQuery);

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


+ 1 - 1
dist/inputmask/jquery.inputmask.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.1.64-99
+* Version: 3.1.64-100
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "./inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery"), require("./inputmask")) : factory(jQuery);

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


+ 5 - 3
dist/jquery.inputmask.bundle.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.1.64-99
+* Version: 3.1.64-100
 */
 !function($) {
     function inputmask(options) {
@@ -2169,7 +2169,8 @@
                 return !1;
             },
             radixHandler: function(chrs, maskset, pos, strict, opts) {
-                if (!strict && chrs === opts.radixPoint && void 0 != opts.digits && (isNaN(opts.digits) || parseInt(opts.digits) > 0)) {
+                if (!strict && (-1 != $.inArray(chrs, [ ",", "." ]) && (chrs = opts.radixPoint), 
+                chrs === opts.radixPoint && void 0 != opts.digits && (isNaN(opts.digits) || parseInt(opts.digits) > 0))) {
                     var radixPos = $.inArray(opts.radixPoint, maskset.buffer), integerValue = maskset.buffer.join("").match(opts.regex.integerPart(opts));
                     if (-1 != radixPos && maskset.validPositions[radixPos]) return maskset.validPositions[radixPos - 1] ? {
                         caret: radixPos + 1
@@ -2180,7 +2181,8 @@
                     };
                     if (!integerValue || "0" == integerValue[0] && integerValue.index + 1 != pos) return maskset.buffer[integerValue ? integerValue.index : pos] = "0", 
                     {
-                        pos: (integerValue ? integerValue.index : pos) + 1
+                        pos: (integerValue ? integerValue.index : pos) + 1,
+                        c: opts.radixPoint
                     };
                 }
                 return !1;

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


+ 20 - 16
js/inputmask.numeric.extensions.js

@@ -301,25 +301,29 @@ Optional extensions on the jquery.inputmask base
 				return false;
 			},
 			radixHandler: function(chrs, maskset, pos, strict, opts) {
-				if (!strict && chrs === opts.radixPoint && (opts.digits != undefined && (isNaN(opts.digits) || parseInt(opts.digits) > 0))) {
-					var radixPos = $.inArray(opts.radixPoint, maskset.buffer),
-						integerValue = maskset.buffer.join('').match(opts.regex.integerPart(opts));
+				if (!strict) {
+					if ($.inArray(chrs, [",", "."]) != -1) chrs = opts.radixPoint;
+					if (chrs === opts.radixPoint && (opts.digits != undefined && (isNaN(opts.digits) || parseInt(opts.digits) > 0))) {
+						var radixPos = $.inArray(opts.radixPoint, maskset.buffer),
+							integerValue = maskset.buffer.join('').match(opts.regex.integerPart(opts));
 
-					if (radixPos != -1 && maskset["validPositions"][radixPos]) {
-						if (maskset["validPositions"][radixPos - 1])
-							return {
+						if (radixPos != -1 && maskset["validPositions"][radixPos]) {
+							if (maskset["validPositions"][radixPos - 1])
+								return {
+									"caret": radixPos + 1
+								};
+							else return {
+								"pos": integerValue.index,
+								c: integerValue[0],
 								"caret": radixPos + 1
 							};
-						else return {
-							"pos": integerValue.index,
-							c: integerValue[0],
-							"caret": radixPos + 1
-						};
-					} else if (!integerValue || (integerValue["0"] == "0" && (integerValue.index + 1) != pos)) {
-						maskset.buffer[integerValue ? integerValue.index : pos] = "0";
-						return {
-							"pos": (integerValue ? integerValue.index : pos) + 1
-						};
+						} else if (!integerValue || (integerValue["0"] == "0" && (integerValue.index + 1) != pos)) {
+							maskset.buffer[integerValue ? integerValue.index : pos] = "0";
+							return {
+								"pos": (integerValue ? integerValue.index : pos) + 1,
+								c: opts.radixPoint
+							};
+						}
 					}
 				}
 				return false;

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "jquery.inputmask",
-  "version": "3.1.64-99",
+  "version": "3.1.64-100",
   "description": "jquery.inputmask is a jquery plugin which create an input mask.",
   "main": "./dist/inputmask/jquery.inputmask.js",
   "files": [

+ 1 - 4
qunit/tests_numeric.js

@@ -596,12 +596,9 @@ test("inputmask(\"decimal\", { digits: 2 }) - value=\"123\" - RomeroMsk", functi
 	$("#testmask").Type("123");
 	$.caret($("#testmask"), 0, 3);
 	$("#testmask").SendKey(",,..");
-	$("#testmask").SendKey(inputmask.keyCode.RIGHT);
-	$("#testmask").SendKey(inputmask.keyCode.RIGHT); //needed in test
-	$("#testmask").SendKey(inputmask.keyCode.RIGHT); //needed in test
 	$("#testmask").Type("45");
 
-	equal($("#testmask").val(), "12345", "Result " + $("#testmask").val());
+	equal($("#testmask").val(), "0.45", "Result " + $("#testmask").val());
 	$("#testmask").remove();
 });