浏览代码

Form not cleaning correctly when AutoUnmask option is set to true fix #1442

Robin Herbots 9 年之前
父节点
当前提交
88cf4c30e9

+ 1 - 0
CHANGELOG.md

@@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
 ### Added
 ### Updates
 ### Fixed
+- Form not cleaning correctly when AutoUnmask option is set to true #1442
 - Form can`t submitted with input[name=disabled] #1473
 
 ## [3.3.4 - 2016-12-22]

+ 1 - 1
bower.json

@@ -1,6 +1,6 @@
 {
   "name": "jquery.inputmask",
-  "version": "3.3.5-4",
+  "version": "3.3.5-8",
   "main": [
 	  "./dist/inputmask/inputmask.dependencyLib",
 	  "./dist/inputmask/inputmask",

+ 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.3.5-4",
+	"version": "3.3.5-8",
 	"keywords": [
 		"jquery",
 		"plugins",

+ 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.3.5-4",
+  "version": "3.3.5-8",
   "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 @@
 * https://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2017 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.3.5-4
+* Version: 3.3.5-8
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "inputmask.dependencyLib", "inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("./inputmask.dependencyLib"), require("./inputmask")) : factory(window.dependencyLib || jQuery, window.Inputmask);

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

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

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

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

+ 9 - 4
dist/inputmask/inputmask.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2017 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.3.5-4
+* Version: 3.3.5-8
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define("inputmask", [ "inputmask.dependencyLib" ], factory) : "object" == typeof exports ? module.exports = factory(require("./inputmask.dependencyLib")) : factory(window.dependencyLib || jQuery);
@@ -13,7 +13,8 @@
         options.alias = alias), this.el = void 0, this.opts = $.extend(!0, {}, this.defaults, options), 
         this.maskset = void 0, this.noMasksCache = options && void 0 !== options.definitions, 
         this.userOptions = options || {}, this.events = {}, this.dataAttribute = "data-inputmask", 
-        this.isRTL = this.opts.numericInput, void resolveAlias(this.opts.alias, options, this.opts)) : new Inputmask(alias, options);
+        this.isRTL = this.opts.numericInput, this.refreshValue = !1, resolveAlias(this.opts.alias, options, this.opts), 
+        void 0) : new Inputmask(alias, options);
     }
     function resolveAlias(aliasStr, options, opts) {
         var aliasDefinition = opts.aliases[aliasStr];
@@ -571,7 +572,10 @@
             }
         }
         function unmaskedvalue(input) {
-            if (input && void 0 === input.inputmask) return input.value;
+            if (input) {
+                if (void 0 === input.inputmask) return input.value;
+                input.inputmask && input.inputmask.refreshValue && EventHandlers.setValueEvent.call(input);
+            }
             var umValue = [], vps = getMaskSet().validPositions;
             for (var pndx in vps) vps[pndx].match && null != vps[pndx].match.fn && umValue.push(vps[pndx].input);
             var unmaskedValue = 0 === umValue.length ? "" : (isRTL ? umValue.reverse() : umValue).join("");
@@ -1017,6 +1021,7 @@
                 }
             },
             setValueEvent: function(e) {
+                this.inputmask.refreshValue = !1;
                 var input = this, value = input.inputmask._valueGet();
                 checkVal(input, !0, !1, ($.isFunction(opts.onBeforeMask) ? opts.onBeforeMask(value, opts) || value : value).split("")), 
                 undoValue = getBuffer().join(""), (opts.clearMaskOnLostFocus || opts.clearIncomplete) && input.inputmask._valueGet() === getBufferTemplate().join("") && input.inputmask._valueSet("");
@@ -1114,7 +1119,7 @@
                 }, 0));
             },
             resetEvent: function(e) {
-                setTimeout(function() {
+                el.inputmask.refreshValue = !0, setTimeout(function() {
                     $el.trigger("setvalue");
                 }, 0);
             }

+ 19 - 19
dist/inputmask/inputmask.numeric.extensions.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2017 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.3.5-4
+* Version: 3.3.5-8
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "inputmask.dependencyLib", "inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("./inputmask.dependencyLib"), require("./inputmask")) : factory(window.dependencyLib || jQuery, window.Inputmask);
@@ -222,20 +222,20 @@
             },
             leadingZeroHandler: function(chrs, maskset, pos, strict, opts, isSelection) {
                 if (!strict) {
-                    var buffer = maskset.buffer.slice("");
-                    if (buffer.splice(0, opts.prefix.length), buffer.splice(buffer.length - opts.suffix.length, opts.suffix.length), 
-                    opts.numericInput === !0) {
-                        var buffer = buffer.reverse(), bufferChar = buffer[0];
-                        if ("0" === bufferChar && void 0 === maskset.validPositions[pos - 1]) return {
-                            pos: pos,
-                            remove: buffer.length - 1
-                        };
-                    } else {
-                        pos -= opts.prefix.length;
-                        var radixPosition = $.inArray(opts.radixPoint, buffer), matchRslt = buffer.slice(0, radixPosition !== -1 ? radixPosition : void 0).join("").match(opts.regex.integerNPart(opts));
-                        if (matchRslt && (radixPosition === -1 || pos <= radixPosition)) {
-                            var decimalPart = radixPosition === -1 ? 0 : parseInt(buffer.slice(radixPosition + 1).join(""));
-                            if (0 === matchRslt[0].indexOf("" !== opts.placeholder ? opts.placeholder.charAt(0) : "0") && (matchRslt.index + 1 === pos || isSelection !== !0 && 0 === decimalPart)) return maskset.buffer.splice(matchRslt.index + opts.prefix.length, 1), 
+                    var initialPos = pos, buffer = opts.numericInput === !0 ? maskset.buffer.slice("").reverse() : maskset.buffer.slice("");
+                    opts.numericInput && (pos = buffer.join("").length - pos - 1), buffer.splice(0, opts.prefix.length), 
+                    buffer.splice(buffer.length - opts.suffix.length, opts.suffix.length), pos -= opts.prefix.length;
+                    var radixPosition = $.inArray(opts.radixPoint, buffer), matchRslt = buffer.slice(0, radixPosition !== -1 ? radixPosition : void 0).join("").match(opts.regex.integerNPart(opts));
+                    if (matchRslt && (radixPosition === -1 || pos <= radixPosition || opts.numericInput)) {
+                        var decimalPart = radixPosition === -1 ? 0 : parseInt(buffer.slice(radixPosition + 1).join("")), leadingZero = 0 === matchRslt[0].indexOf("" !== opts.placeholder ? opts.placeholder.charAt(0) : "0");
+                        if (opts.numericInput) {
+                            if (leadingZero && 0 !== decimalPart && isSelection !== !0) return maskset.buffer.splice(buffer.length - matchRslt.index - 1 + opts.suffix.length, 1), 
+                            {
+                                pos: initialPos,
+                                remove: buffer.length - matchRslt.index - 1 + opts.suffix.length
+                            };
+                        } else {
+                            if (leadingZero && (matchRslt.index + 1 === pos || isSelection !== !0 && 0 === decimalPart)) return maskset.buffer.splice(matchRslt.index + opts.prefix.length, 1), 
                             {
                                 pos: matchRslt.index + opts.prefix.length,
                                 remove: matchRslt.index + opts.prefix.length
@@ -253,7 +253,7 @@
                         if (!isValid && (isValid = opts.radixHandler(chrs, maskset, pos, strict, opts), 
                         !isValid && (isValid = strict ? new RegExp("[0-9" + Inputmask.escapeRegex(opts.groupSeparator) + "]").test(chrs) : new RegExp("[0-9]").test(chrs), 
                         isValid === !0 && (isValid = opts.leadingZeroHandler(chrs, maskset, pos, strict, opts, isSelection), 
-                        isValid === !0)))) {
+                        isValid === !0 && opts.numericInput !== !0)))) {
                             var radixPosition = $.inArray(opts.radixPoint, maskset.buffer);
                             isValid = radixPosition !== -1 && (opts.digitsOptional === !1 || maskset.validPositions[pos]) && opts.numericInput !== !0 && pos > radixPosition && !strict ? {
                                 pos: pos,
@@ -328,10 +328,10 @@
                 isFinite(processValue);
             },
             onBeforeMask: function(initialValue, opts) {
-                if (opts.numericInput === !0 && (initialValue = initialValue.split("").reverse().join("")), 
+                if (initialValue = initialValue.toString(), opts.numericInput === !0 && (initialValue = initialValue.split("").reverse().join("")), 
                 "" !== opts.radixPoint && isFinite(initialValue)) {
                     var vs = initialValue.split("."), groupSize = "" !== opts.groupSeparator ? parseInt(opts.groupSize) : 0;
-                    2 === vs.length && (vs[0].length > groupSize || vs[1].length > groupSize) && (initialValue = initialValue.toString().replace(".", opts.radixPoint));
+                    2 === vs.length && (vs[0].length > groupSize || vs[1].length > groupSize) && (initialValue = initialValue.replace(".", opts.radixPoint));
                 }
                 var kommaMatches = initialValue.match(/,/g), dotMatches = initialValue.match(/\./g);
                 if (dotMatches && kommaMatches ? dotMatches.length > kommaMatches.length ? (initialValue = initialValue.replace(/\./g, ""), 
@@ -348,7 +348,7 @@
                     }
                 }
                 return opts.numericInput === !0 && (initialValue = initialValue.split("").reverse().join("")), 
-                initialValue.toString();
+                initialValue;
             },
             canClearPosition: function(maskset, position, lvp, strict, opts) {
                 var positionInput = maskset.validPositions[position].input, canClear = positionInput !== opts.radixPoint || null !== maskset.validPositions[position].match.fn && opts.decimalProtect === !1 || isFinite(positionInput) || position === lvp || positionInput === opts.groupSeparator || positionInput === opts.negationSymbol.front || positionInput === opts.negationSymbol.back;

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

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

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

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

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

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

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


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


+ 1 - 1
dist/min/inputmask/inputmask.dependencyLib.min.js

@@ -3,6 +3,6 @@
 * https://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2017 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.3.5-4
+* Version: 3.3.5-8
 */
 !function(a){"function"==typeof define&&define.amd?define("inputmask.dependencyLib",["jquery"],a):"object"==typeof exports?module.exports=a(require("jquery")):a(jQuery)}(function(a){return window.dependencyLib=a,a});

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


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


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


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


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


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


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


文件差异内容过多而无法显示
+ 2615 - 2608
js/inputmask.js


+ 28 - 25
js/inputmask.numeric.extensions.js

@@ -131,8 +131,7 @@
 			negationSymbol: {
 				front: "-", //"("
 				back: "" //")"
-			}
-			,
+			},
 			integerDigits: "+", //number of integerDigits
 			integerOptional: true,
 			prefix: "",
@@ -442,26 +441,30 @@
 			,
 			leadingZeroHandler: function (chrs, maskset, pos, strict, opts, isSelection) {
 				if (!strict) {
-					var buffer = maskset.buffer.slice("");
+					var initialPos = pos,
+						buffer = opts.numericInput === true ? maskset.buffer.slice("").reverse() : maskset.buffer.slice("");
+					if (opts.numericInput) {
+						pos = buffer.join("").length - pos - 1;
+					}
 					buffer.splice(0, opts.prefix.length);
 					buffer.splice(buffer.length - opts.suffix.length, opts.suffix.length);
-					if (opts.numericInput === true) {
-						var buffer = buffer.reverse();
-						var bufferChar = buffer[0];
-						if (bufferChar === "0" && maskset.validPositions[pos - 1] === undefined) {
-							return {
-								"pos": pos,
-								"remove": buffer.length - 1
-							};
-						}
-					} else {
-						pos = pos - opts.prefix.length;
-						var radixPosition = $.inArray(opts.radixPoint, buffer),
-							matchRslt = buffer.slice(0, radixPosition !== -1 ? radixPosition : undefined).join("").match(opts.regex.integerNPart(opts));
-						if (matchRslt && (radixPosition === -1 || pos <= radixPosition)) {
-							var decimalPart = radixPosition === -1 ? 0 : parseInt(buffer.slice(radixPosition + 1).join(""));
-							if (matchRslt["0"].indexOf(opts.placeholder !== "" ? opts.placeholder.charAt(0) : "0") === 0 &&
-								(matchRslt.index + 1 === pos || (isSelection !== true && decimalPart === 0))) {
+
+					pos = pos - opts.prefix.length;
+					var radixPosition = $.inArray(opts.radixPoint, buffer),
+						matchRslt = buffer.slice(0, radixPosition !== -1 ? radixPosition : undefined).join("").match(opts.regex.integerNPart(opts));
+					if (matchRslt && (radixPosition === -1 || pos <= radixPosition || opts.numericInput)) {
+						var decimalPart = radixPosition === -1 ? 0 : parseInt(buffer.slice(radixPosition + 1).join("")),
+							leadingZero = matchRslt["0"].indexOf(opts.placeholder !== "" ? opts.placeholder.charAt(0) : "0") === 0;
+						if (opts.numericInput) {
+							if (leadingZero && decimalPart !== 0 && isSelection !== true) {
+								maskset.buffer.splice((buffer.length - matchRslt.index - 1) + opts.suffix.length, 1);
+								return {
+									"pos": initialPos,
+									"remove": (buffer.length - matchRslt.index - 1) + opts.suffix.length
+								};
+							}
+						} else {
+							if (leadingZero && (matchRslt.index + 1 === pos || (isSelection !== true && decimalPart === 0))) {
 								maskset.buffer.splice(matchRslt.index + opts.prefix.length, 1);
 								return {
 									"pos": matchRslt.index + opts.prefix.length,
@@ -474,8 +477,7 @@
 					}
 				}
 				return true;
-			}
-			,
+			},
 			definitions: {
 				"~": {
 					validator: function (chrs, maskset, pos, strict, opts, isSelection) {
@@ -486,7 +488,7 @@
 								isValid = strict ? new RegExp("[0-9" + Inputmask.escapeRegex(opts.groupSeparator) + "]").test(chrs) : new RegExp("[0-9]").test(chrs);
 								if (isValid === true) {
 									isValid = opts.leadingZeroHandler(chrs, maskset, pos, strict, opts, isSelection);
-									if (isValid === true) {
+									if (isValid === true && opts.numericInput !== true) {
 										//handle overwrite when fixed precision
 										var radixPosition = $.inArray(opts.radixPoint, maskset.buffer);
 										if (radixPosition !== -1 && (opts.digitsOptional === false || maskset.validPositions[pos]) && opts.numericInput !== true && pos > radixPosition && !strict) {
@@ -607,6 +609,7 @@
 			}
 			,
 			onBeforeMask: function (initialValue, opts) {
+				initialValue = initialValue.toString();
 				if (opts.numericInput === true) {
 					initialValue = initialValue.split("").reverse().join("");
 				}
@@ -614,7 +617,7 @@
 					var vs = initialValue.split("."),
 						groupSize = opts.groupSeparator !== "" ? parseInt(opts.groupSize) : 0;
 					if (vs.length === 2 && (vs[0].length > groupSize || vs[1].length > groupSize))
-						initialValue = initialValue.toString().replace(".", opts.radixPoint);
+						initialValue = initialValue.replace(".", opts.radixPoint);
 				}
 				var kommaMatches = initialValue.match(/,/g);
 				var dotMatches = initialValue.match(/\./g);
@@ -655,7 +658,7 @@
 				if (opts.numericInput === true) {
 					initialValue = initialValue.split("").reverse().join("");
 				}
-				return initialValue.toString();
+				return initialValue;
 			},
 			canClearPosition: function (maskset, position, lvp, strict, opts) {
 				var positionInput = maskset.validPositions[position].input,

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
 	"name": "jquery.inputmask",
-	"version": "3.3.5-4",
+	"version": "3.3.5-8",
 	"description": "jquery.inputmask is a jquery plugin which create an input mask.",
 	"main": "index.js",
 	"files": [

+ 6 - 0
qunit/tests_formatvalidate.js

@@ -56,6 +56,10 @@ define([
 		assert.equal(formattedValue, "(555) 111-2222", "Result " + formattedValue);
 	});
 
+	qunit.test("format(62.91, { alias: 'numeric' } - penihel", function(assert) {
+		var formattedValue = 	Inputmask.format(62.91, { alias: 'numeric' });
+		assert.equal(formattedValue, "62.91", "Result " + formattedValue);
+	});
 
 	qunit.module("Value Validating");
 	qunit.test("Inputmask.isValid(\"23/03/1973\", { alias: \"date\"})", function(assert) {
@@ -228,4 +232,6 @@ define([
 		});
 		assert.equal(unmasked, "23031973", "Result " + unmasked);
 	});
+
+
 });