Browse Source

wip keepstatic

Robin Herbots 6 years ago
parent
commit
a9b73081d6

+ 15 - 0
.vscode/launch.json

@@ -0,0 +1,15 @@
+{
+    // Use IntelliSense to learn about possible attributes.
+    // Hover to view descriptions of existing attributes.
+    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
+    "version": "0.2.0",
+    "configurations": [
+        {
+            "type": "chrome",
+            "request": "launch",
+            "name": "Launch Chrome file",
+            "url": "${file}",
+            "webRoot": "${workspaceFolder}"
+        }
+    ]
+}

+ 4 - 0
.vscode/settings.json

@@ -0,0 +1,4 @@
+{
+    "abl.checkProgressBinary": false,
+    "abl.warnConfigFile": false
+}

+ 5 - 0
CHANGELOG.md

@@ -9,6 +9,10 @@
 - add insertModeVisual option
 
 ### Updates
+- onKeyValidation: add position to parameters 
+- change behavior of keepStatic option
+    - multiple masks => default true
+    - all other masks => default false
 - add more tokens for datetime format
 - refactor inputfallbackevent
 - drop colormask support
@@ -58,6 +62,7 @@
 - Document bug with disabled inputs caused by Firefox 64 and older #2045
 - Behaviour of v3 with hours not possible anymore #1918
 - Unmasked value of datetime alias, if empty, returns the placeholder #2039
+- ...
 
 ## [4.0.4 - 2018-12-03]
 ### Addition

+ 2 - 2
README.md

@@ -941,7 +941,7 @@ $(document).ready(function(){
 ```
 
 ### onKeyValidation
-Callback function is executed on every keyvalidation with the key & result as parameter.
+Callback function is executed on every keyvalidation with the key, result as parameter.
 
 ```javascript
 $(document).ready(function(){
@@ -991,7 +991,7 @@ ex. $(selector).inputmask({ mask: ["+55-99-9999-9999", "+55-99-99999-9999", ], k
 
 typing 1212345123 => should result in +55-12-1234-5123 type extra 4 => switch to +55-12-12345-1234
 
-When passing multiple masks (an array of masks) keepStatic is automatically set to true unless explicitly set through the options.
+**When the option is not set, it will default to false, except for multiple masks it will default to true!!**
 
 ### positionCaretOnTab
 When enabled the caret position is set after the latest valid position on TAB Default: true

File diff suppressed because it is too large
+ 5689 - 2534
dist/inputmask.js


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


+ 64 - 35
lib/extensions/inputmask.date.extensions.js

@@ -114,8 +114,8 @@ function getTokenizer(opts) {
 
 function isValidDate(dateParts, currentResult) {
 	return !isFinite(dateParts.rawday)
-	|| (dateParts.day == "29" && !isFinite(dateParts.rawyear))
-	|| new Date(dateParts.date.getFullYear(), isFinite(dateParts.rawmonth) ? dateParts.month : dateParts.date.getMonth() + 1, 0).getDate() >= dateParts.day
+		|| (dateParts.day == "29" && !isFinite(dateParts.rawyear))
+		|| new Date(dateParts.date.getFullYear(), isFinite(dateParts.rawmonth) ? dateParts.month : dateParts.date.getMonth() + 1, 0).getDate() >= dateParts.day
 		? currentResult
 		: false; //take corrective action if possible
 }
@@ -190,7 +190,7 @@ function pad(val, len) {
 }
 
 function analyseMask(maskString, format, opts) {
-	var dateObj = {"date": new Date(1, 0, 1)}, targetProp, mask = maskString, match, dateOperation;
+	var dateObj = { "date": new Date(1, 0, 1) }, targetProp, mask = maskString, match, dateOperation;
 
 	function extendProperty(value) {
 		var correctedValue = value.replace(/[^0-9]/g, "0");
@@ -237,6 +237,43 @@ function analyseMask(maskString, format, opts) {
 	return undefined;
 }
 
+function importDate(dateObj, opts) {
+	var match, date = "";
+
+	getTokenizer(opts).lastIndex = 0;
+	while ((match = getTokenizer(opts).exec(opts.inputFormat))) {
+		if (match[0].charAt(0) === "d") {
+			date += pad(dateObj.getDate(), match[0].length);
+		} else if (match[0].charAt(0) === "m") {
+			date += pad((dateObj.getMonth() + 1), match[0].length);
+		} else if (match[0] === "yyyy") {
+			date += dateObj.getFullYear().toString();
+		} else if (match[0].charAt(0) === "y") {
+			date += pad(dateObj.getYear(), match[0].length);
+		}
+	}
+
+	return date;
+}
+
+function getTokenMatch(pos, opts) {
+	var calcPos = 0, targetMatch, match;
+	getTokenizer(opts).lastIndex = 0;
+	while ((match = getTokenizer(opts).exec(opts.inputFormat))) {
+		calcPos += match[0].length;
+		if (calcPos >= pos) {
+			targetMatch = match;
+			match = getTokenizer(opts).exec(opts.inputFormat);
+			break;
+		}
+	}
+	return {
+		nextMatch: match,
+		targetMatch: targetMatch
+	};
+}
+
+
 Inputmask.extendAliases({
 	"datetime": {
 		mask: function (opts) {
@@ -248,7 +285,8 @@ Inputmask.extendAliases({
 			opts.outputFormat = formatAlias[opts.outputFormat] || opts.outputFormat || opts.inputFormat; //resolve possible formatAlias
 			opts.placeholder = opts.placeholder !== "" ? opts.placeholder : opts.inputFormat.replace(/[[\]]/, "");
 			opts.regex = parse(opts.inputFormat, undefined, opts);
-			// console.log(opts.regex);
+			opts.min = analyseMask(opts.min, opts.inputFormat, opts);
+			opts.max = analyseMask(opts.max, opts.inputFormat, opts);
 			return null; //migrate to regex mask
 		},
 		placeholder: "", //set default as none (~ auto); when a custom placeholder is passed it will be used
@@ -272,24 +310,15 @@ Inputmask.extendAliases({
 		},
 		preValidation: function (buffer, pos, c, isSelection, opts, maskset, caretPos, strict) {
 			if (strict) return true;
-			var calcPos = 0, targetMatch, match;
 			if (isNaN(c) && buffer[pos] !== c) {
-				getTokenizer(opts).lastIndex = 0;
-				while ((match = getTokenizer(opts).exec(opts.inputFormat))) {
-					calcPos += match[0].length;
-					if (calcPos >= pos) {
-						targetMatch = match;
-						match = getTokenizer(opts).exec(opts.inputFormat);
-						break;
-					}
-				}
-				if (match && match[0] === c && targetMatch[0].length > 1) {
+				var tokenMatch = getTokenMatch(pos, opts);
+				if (tokenMatch.nextMatch && tokenMatch.nextMatch[0] === c && tokenMatch.targetMatch[0].length > 1) {
 					buffer[pos] = buffer[pos - 1];
 					buffer[pos - 1] = "0";
 					return {
 						fuzzy: true,
 						buffer: buffer,
-						refreshFromBuffer: {start: pos - 1, end: pos + 1},
+						refreshFromBuffer: { start: pos - 1, end: pos + 1 },
 						pos: pos + 1
 					};
 				}
@@ -297,9 +326,17 @@ Inputmask.extendAliases({
 			return true;
 		},
 		postValidation: function (buffer, pos, currentResult, opts, maskset, strict) {
+			if (currentResult === false) {
+				var tokenMatch = getTokenMatch(pos, opts);
+				if (tokenMatch.targetMatch && tokenMatch.targetMatch.index === pos && tokenMatch.targetMatch[0].length > 1) {
+					//FIXME
+				}
+			}
+
+
 			if (strict) return true;
-			opts.min = analyseMask(opts.min, opts.inputFormat, opts);
-			opts.max = analyseMask(opts.max, opts.inputFormat, opts);
+			// opts.min = analyseMask(opts.min, opts.inputFormat, opts);
+			// opts.max = analyseMask(opts.max, opts.inputFormat, opts);
 
 			if (currentResult.fuzzy) {
 				buffer = currentResult.buffer;
@@ -332,7 +369,7 @@ Inputmask.extendAliases({
 			if (pos && result && currentResult.pos !== pos) {
 				return {
 					buffer: parse(opts.inputFormat, dateParts, opts).split(""),
-					refreshFromBuffer: {start: pos, end: currentResult.pos}
+					refreshFromBuffer: { start: pos, end: currentResult.pos }
 				};
 			}
 
@@ -341,22 +378,7 @@ Inputmask.extendAliases({
 		onKeyDown: function (e, buffer, caretPos, opts) {
 			var input = this;
 			if (e.ctrlKey && e.keyCode === keyCode.RIGHT) {
-				var today = new Date(), match, date = "";
-
-				getTokenizer(opts).lastIndex = 0;
-				while ((match = getTokenizer(opts).exec(opts.inputFormat))) {
-					if (match[0].charAt(0) === "d") {
-						date += pad(today.getDate(), match[0].length);
-					} else if (match[0].charAt(0) === "m") {
-						date += pad((today.getMonth() + 1), match[0].length);
-					} else if (match[0] === "yyyy") {
-						date += today.getFullYear().toString();
-					} else if (match[0].charAt(0) === "y") {
-						date += pad(today.getYear(), match[0].length);
-					}
-				}
-
-				input.inputmask._valueSet(date);
+				input.inputmask._valueSet(importDate(new Date(), opts));
 				$(input).trigger("setvalue");
 			}
 		},
@@ -368,6 +390,13 @@ Inputmask.extendAliases({
 			if (test.nativeDef.indexOf("[AP]") == 0) return elem.toUpperCase();
 			return elem;
 		},
+		onBeforeMask: function (initialValue, opts) {
+			if (Object.prototype.toString.call(initialValue) === "[object Date]") {
+				initialValue = importDate(initialValue, opts);
+			}
+
+			return initialValue;
+		},
 		insertMode: false,
 		shiftPositions: false,
 		keepStatic: false,

+ 16 - 15
lib/extensions/inputmask.numeric.extensions.js

@@ -45,7 +45,7 @@ function alignDigits(buffer, digits, opts, force) {
 function findValidator(symbol, maskset) {
 	var posNdx = 0;
 	if (symbol === "+") {
-		for (posNdx in maskset.validPositions) ;
+		for (posNdx in maskset.validPositions);
 		posNdx = parseInt(posNdx);
 	}
 	for (var tstNdx in maskset.tests) {
@@ -246,7 +246,7 @@ Inputmask.extendAliases({
 		unmaskAsNumber: false,
 		roundingFN: Math.round, //Math.floor ,  fn(x)
 		inputmode: "numeric",
-		shortcuts: {k: "000", m: "000000"},
+		shortcuts: { k: "000", m: "000000" },
 		//global options
 		placeholder: "0",
 		greedy: false,
@@ -282,7 +282,7 @@ Inputmask.extendAliases({
 				if (pattern.length > 1) {
 					var inserts = [];
 					for (var i = 0; i < pattern.length; i++) {
-						inserts.push({pos: pos + i, c: pattern[i], strict: false});
+						inserts.push({ pos: pos + i, c: pattern[i], strict: false });
 					}
 				}
 				return {
@@ -305,11 +305,11 @@ Inputmask.extendAliases({
 					remove: isNegative,
 					caret: initPos
 				} : {
-					insert: [
-						{pos: findValidator("+", maskset), c: opts.negationSymbol.front, fromIsValid: true},
-						{pos: findValidator("-", maskset), c: opts.negationSymbol.back, fromIsValid: undefined}],
-					caret: initPos + opts.negationSymbol.back.length
-				};
+						insert: [
+							{ pos: findValidator("+", maskset), c: opts.negationSymbol.front, fromIsValid: true },
+							{ pos: findValidator("-", maskset), c: opts.negationSymbol.back, fromIsValid: undefined }],
+						caret: initPos + opts.negationSymbol.back.length
+					};
 			}
 
 			if (strict) return true;
@@ -320,25 +320,26 @@ Inputmask.extendAliases({
 			}
 			if (isSelection && opts.__financeInput === false) {
 				if (opts.digitsOptional) {
-					return {rewritePosition: caretPos.end};
+					return { rewritePosition: caretPos.end };
 				} else if (!opts.digitsOptional) {
 					if (caretPos.begin > radixPos && caretPos.end <= radixPos) {
 						if (c === opts.radixPoint) {
 							return {
-								insert: {pos: radixPos + 1, c: "0", fromIsValid: true},
+								insert: { pos: radixPos + 1, c: "0", fromIsValid: true },
 								rewritePosition: radixPos
 							};
 						} else {
-							return {rewritePosition: radixPos + 1};
+							return { rewritePosition: radixPos + 1 };
 						}
 					} else if (caretPos.begin < radixPos) {
-						return {rewritePosition: caretPos.begin - 1};
+						return { rewritePosition: caretPos.begin - 1 };
 					}
 				}
 			}
-			return {rewritePosition: pos};
+			return { rewritePosition: pos };
 		},
 		postValidation: function (buffer, pos, currentResult, opts, maskset, strict) {
+			if (currentResult === false) return currentResult;
 			if (strict) return true;
 			if (opts.min !== null || opts.max !== null) {
 				var unmasked = opts.onUnMask(buffer.slice().reverse().join(""), undefined, $.extend({}, opts, {
@@ -491,7 +492,7 @@ Inputmask.extendAliases({
 							var nmbrMtchs = new RegExp("(^" + (opts.negationSymbol.front != "" ? Inputmask.escapeRegex(opts.negationSymbol.front) + "?" : "") + Inputmask.escapeRegex(opts.prefix) + ")(.*)(" + Inputmask.escapeRegex(opts.suffix) + (opts.negationSymbol.back != "" ? Inputmask.escapeRegex(opts.negationSymbol.back) + "?" : "") + "$)").exec(stripBuffer(buffer.slice(), true).reverse().join("")),
 								number = nmbrMtchs ? nmbrMtchs[2] : "";
 							if (number == 0) {
-								result = {refreshFromBuffer: true, buffer: [0]};
+								result = { refreshFromBuffer: true, buffer: [0] };
 							}
 						} else if (opts.radixPoint !== "" && buffer[0] === opts.radixPoint) { //strip radixpoint on blur when it is the latest char
 							if (result && result.buffer) {
@@ -499,7 +500,7 @@ Inputmask.extendAliases({
 							} else {
 								buffer.shift();
 								result =
-									{refreshFromBuffer: true, buffer: stripBuffer(buffer)};
+									{ refreshFromBuffer: true, buffer: stripBuffer(buffer) };
 							}
 						}
 

+ 4 - 4
lib/inputmask.js

@@ -81,7 +81,7 @@ Inputmask.prototype = {
 		_radixDance: false, //dance around the radixPoint
 		groupSeparator: "", //",", // | "."
 		//numeric basic properties
-		keepStatic: null, //try to keep the mask static while typing. Decisions to alter the mask will be posponed if possible - null see auto selection for multi masks
+		keepStatic: null, //try to keep the mask static while typing. Decisions to alter the mask will be posponed if possible
 		positionCaretOnTab: true, //when enabled the caret position is set after the latest valid position on TAB
 		tabThrough: false, //allows for tabbing through the different parts of the masked field
 		supportsInputType: ["text", "tel", "url", "password", "search"], //list with the supported input types
@@ -226,9 +226,9 @@ function resolveAlias(aliasStr, options, opts) {
 		$.extend(true, opts, options); //reapply extra given options
 		return true;
 	} else //alias not found - try as mask
-	if (opts.mask === null) {
-		opts.mask = aliasStr;
-	}
+		if (opts.mask === null) {
+			opts.mask = aliasStr;
+		}
 
 	return false;
 }

+ 26 - 30
lib/maskScope.js

@@ -55,11 +55,6 @@ module.exports = function maskScope(actionObj, maskset, opts) {
 					maskTemplate.push(includeMode === false ? test.nativeDef : getPlaceholder(pos, test));
 				}
 			}
-			if (opts.keepStatic === "auto") {
-				if (test.newBlockMarker && test.static !== true) {
-					opts.keepStatic = pos - 1;
-				}
-			}
 
 			pos++;
 		} while ((maxLength === undefined || pos < maxLength) && (test.static !== true || test.def !== "") || minimalPos > pos);
@@ -540,7 +535,7 @@ module.exports = function maskScope(actionObj, maskset, opts) {
 			maskset.tests = {}; //refresh tests after possible alternating
 			start = 0;
 			end = buffer.length;
-			p = determineNewCaretPosition({begin: 0, end: 0}, false).begin;
+			p = determineNewCaretPosition({ begin: 0, end: 0 }, false).begin;
 		} else {
 			for (i = start; i < end; i++) {
 				delete maskset.validPositions[i];
@@ -686,7 +681,7 @@ module.exports = function maskScope(actionObj, maskset, opts) {
 						returnRslt = isValidRslt;
 					}
 					if (maskPos == true && isValidRslt) {  //return validposition on generalise
-						returnRslt = {caretPos: i};
+						returnRslt = { caretPos: i };
 					}
 				}
 				if (!isValidRslt) {
@@ -739,7 +734,7 @@ module.exports = function maskScope(actionObj, maskset, opts) {
 					$.each(commandObj.remove.sort(function (a, b) {
 						return b.pos - a.pos;
 					}), function (ndx, lmnt) {
-						revalidateMask({begin: lmnt, end: lmnt + 1});
+						revalidateMask({ begin: lmnt, end: lmnt + 1 });
 					});
 					commandObj.remove = undefined;
 				}
@@ -849,7 +844,7 @@ module.exports = function maskScope(actionObj, maskset, opts) {
 							if (pos.end > maskPos) {
 								maskset.validPositions[maskPos] = undefined;
 							}
-							if (!skip && !isMask(maskPos, true)) {
+							if (!skip && !isMask(maskPos, opts.keepStatic)) {
 								for (var nPos = maskPos + 1, snPos = seekNext(maskPos); nPos <= snPos; nPos++) {
 									// if (!isMask(nPos, true)) {
 									// 	continue;
@@ -870,9 +865,9 @@ module.exports = function maskScope(actionObj, maskset, opts) {
 			}
 
 
-			if (result === false && (opts.keepStatic === false || isComplete(getBuffer()) || maskPos === 0) && !strict && fromAlternate !== true) { //try fuzzy alternator logic
+			if (result === false && opts.keepStatic && (isComplete(getBuffer()) || maskPos === 0) && !strict && fromAlternate !== true) { //try fuzzy alternator logic
 				result = alternate(maskPos, c, strict, fromIsValid, undefined, pos);
-			} else if (isSelection(pos) && maskset.tests[maskPos] && maskset.tests[maskPos].length > 1 && opts.keepStatic === true && !strict && fromAlternate !== true) { //selection clears an alternated keepstatic mask ~ #2189
+			} else if (isSelection(pos) && maskset.tests[maskPos] && maskset.tests[maskPos].length > 1 && opts.keepStatic && !strict && fromAlternate !== true) { //selection clears an alternated keepstatic mask ~ #2189
 				result = alternate(true);
 			}
 
@@ -882,7 +877,7 @@ module.exports = function maskScope(actionObj, maskset, opts) {
 				};
 			}
 		}
-		if ($.isFunction(opts.postValidation) && result !== false && fromIsValid !== true && validateOnly !== true) {
+		if ($.isFunction(opts.postValidation) && fromIsValid !== true && validateOnly !== true) {
 			var postResult = opts.postValidation(getBuffer(true), pos.begin !== undefined ? (isRTL ? pos.end : pos.begin) : pos, result, opts, maskset, strict);
 			if (postResult !== undefined) {
 				result = postResult === true ? result : postResult;
@@ -1048,7 +1043,7 @@ module.exports = function maskScope(actionObj, maskset, opts) {
 
 		if (strict !== true && pos > -1) {
 			var tests = getTests(pos);
-			return tests.length > 1 + (tests[tests.length - 1].match.def === "" ? 1 : 0);
+			return tests.length > (1 + (tests[tests.length - 1].match.def === "" ? 1 : 0));
 		}
 		return false;
 	}
@@ -1057,8 +1052,8 @@ module.exports = function maskScope(actionObj, maskset, opts) {
 		if (fuzzy === undefined) fuzzy = true;
 		var position = pos + 1;
 		while (getTest(position).match.def !== "" &&
-		((newBlock === true && (getTest(position).match.newBlockMarker !== true || !isMask(position, undefined, true))) ||
-			(newBlock !== true && !isMask(position, undefined, fuzzy)))) {
+			((newBlock === true && (getTest(position).match.newBlockMarker !== true || !isMask(position, undefined, true))) ||
+				(newBlock !== true && !isMask(position, undefined, fuzzy)))) {
 			position++;
 		}
 		return position;
@@ -1070,10 +1065,10 @@ module.exports = function maskScope(actionObj, maskset, opts) {
 		if (position <= 0) return 0;
 
 		while (--position > 0 &&
-		((newBlock === true && getTest(position).match.newBlockMarker !== true) ||
-			(newBlock !== true && !isMask(position, undefined, true) &&
-				// eslint-disable-next-line no-empty
-				(tests = getTests(position), tests.length < 2 || (tests.length === 2 && tests[1].match.def === ""))))) {
+			((newBlock === true && getTest(position).match.newBlockMarker !== true) ||
+				(newBlock !== true && !isMask(position, undefined, true) &&
+					// eslint-disable-next-line no-empty
+					(tests = getTests(position), tests.length < 2 || (tests.length === 2 && tests[1].match.def === ""))))) {
 		}
 		return position;
 	}
@@ -1194,7 +1189,7 @@ module.exports = function maskScope(actionObj, maskset, opts) {
 				case "none":
 					break;
 				case "select":
-					selectedCaret = {begin: 0, end: getBuffer().length};
+					selectedCaret = { begin: 0, end: getBuffer().length };
 					break;
 				case "ignore":
 					selectedCaret.end = selectedCaret.begin = seekNext(getLastValidPosition());
@@ -1420,9 +1415,9 @@ module.exports = function maskScope(actionObj, maskset, opts) {
 				//special treat the decimal separator
 				if ((k === 44 || k === 46) && e.location === 3 && opts.radixPoint !== "") k = opts.radixPoint.charCodeAt(0);
 				var pos = checkval ? {
-						begin: ndx,
-						end: ndx
-					} : caret(input),
+					begin: ndx,
+					end: ndx
+				} : caret(input),
 					forwardPosition, c = String.fromCharCode(k);
 
 				maskset.writeOutBuffer = true;
@@ -1435,8 +1430,9 @@ module.exports = function maskScope(actionObj, maskset, opts) {
 
 				forwardPosition = ((opts.numericInput && valResult.caret === undefined) ? seekPrevious(forwardPosition) : forwardPosition);
 				if (writeOut !== false) {
+
 					setTimeout(function () {
-						opts.onKeyValidation.call(input, k, valResult, opts);
+						opts.onKeyValidation.call(input, k, valResult);
 					}, 0);
 					if (maskset.writeOutBuffer && valResult !== false) {
 						var buffer = getBuffer();
@@ -1801,15 +1797,15 @@ module.exports = function maskScope(actionObj, maskset, opts) {
 					|| (getTest(ndx).match.nativeDef === " " && (getTest(ndx + 1).match.nativeDef === charCodes.charAt(0)
 						|| (getTest(ndx + 1).match.static === true && getTest(ndx + 1).match.nativeDef === ("'" + charCodes.charAt(0))))));
 
-			if (!match && charCodeNdx > 0) inputmask.caretPos = {begin: seekNext(charCodeNdx)};
+			if (!match && charCodeNdx > 0) inputmask.caretPos = { begin: seekNext(charCodeNdx) };
 			return match;
 		}
 
 		resetMaskSet();
 		maskset.tests = {}; //reset tests ~ possible after alternating
-		initialNdx = opts.radixPoint ? determineNewCaretPosition({begin: 0, end: 0}).begin : 0;
+		initialNdx = opts.radixPoint ? determineNewCaretPosition({ begin: 0, end: 0 }).begin : 0;
 		maskset.p = initialNdx;
-		inputmask.caretPos = {begin: initialNdx};
+		inputmask.caretPos = { begin: initialNdx };
 
 		var staticMatches = [], prevCaretPos = inputmask.caretPos;
 		$.each(inputValue, function (ndx, charCode) {
@@ -1840,7 +1836,7 @@ module.exports = function maskScope(actionObj, maskset, opts) {
 							}
 						}
 						writeBuffer(undefined, getBuffer(), result.forwardPosition, keypress, false);
-						inputmask.caretPos = {begin: result.forwardPosition, end: result.forwardPosition};
+						inputmask.caretPos = { begin: result.forwardPosition, end: result.forwardPosition };
 						prevCaretPos = inputmask.caretPos;
 					} else {
 						inputmask.caretPos = prevCaretPos;
@@ -1935,7 +1931,7 @@ module.exports = function maskScope(actionObj, maskset, opts) {
 
 				var scrollCalc = parseInt(((input.ownerDocument.defaultView || window).getComputedStyle ? (input.ownerDocument.defaultView || window).getComputedStyle(input, null) : input.currentStyle).fontSize) * end;
 				input.scrollLeft = scrollCalc > input.scrollWidth ? scrollCalc : 0;
-				input.inputmask.caretPos = {begin: begin, end: end}; //track caret internally
+				input.inputmask.caretPos = { begin: begin, end: end }; //track caret internally
 				if (opts.insertModeVisual && opts.insertMode === false && begin === end) end++; //set visualization for insert/overwrite mode
 				if (input === document.activeElement) {
 					if ("setSelectionRange" in input) {
@@ -2461,4 +2457,4 @@ module.exports = function maskScope(actionObj, maskset, opts) {
 		}
 	}
 }
-;
+	;

+ 1 - 8
lib/maskset.js

@@ -60,13 +60,7 @@ function generateMaskSet(opts, nocache) {
 	if ($.isArray(opts.mask)) {
 		if (opts.mask.length > 1) {
 			if (opts.keepStatic === null) { //enable by default when passing multiple masks when the option is not explicitly specified
-				opts.keepStatic = "auto";
-				for (var i = 0; i < opts.mask.length; i++) { //multiple mask startting with different mask
-					if (opts.mask[i].charAt(0) !== opts.mask[0].charAt(0)) {
-						opts.keepStatic = true;
-						break;
-					}
-				}
+				opts.keepStatic = true;
 			}
 			var altMask = opts.groupmarker[0];
 			$.each(opts.isRTL ? opts.mask.reverse() : opts.mask, function (ndx, msk) {
@@ -86,7 +80,6 @@ function generateMaskSet(opts, nocache) {
 			opts.mask = opts.mask.pop();
 		}
 	}
-
 	if (opts.keepStatic === null) opts.keepStatic = false;
 	if (opts.mask && opts.mask.mask !== undefined && !$.isFunction(opts.mask.mask)) {
 		ms = generateMask(opts.mask.mask, opts.mask, opts);

+ 10 - 10
package.json

@@ -36,18 +36,18 @@
   },
   "homepage": "https://github.com/RobinHerbots/Inputmask",
   "devDependencies": {
-    "@babel/core": "^7.5.4",
-    "@babel/plugin-transform-modules-commonjs": "^7.5.0",
+    "@babel/core": "^7.7.2",
+    "@babel/plugin-transform-modules-commonjs": "^7.7.0",
     "babel-loader": "^8.0.6",
-    "@babel/preset-env": "^7.5.4",
+    "@babel/preset-env": "^7.7.1",
     "jqlite": "^0.2.42",
     "jquery": "^3.4.1",
-    "jsdom": "^15.1.1",
-    "load-grunt-tasks": "^5.0.0",
-    "qunit": "^2.9.2",
-    "uglifyjs-webpack-plugin": "^2.1.3",
-    "webpack": "^4.35.3",
-    "webpack-cli": "^3.3.6",
+    "jsdom": "^15.2.1",
+    "load-grunt-tasks": "^5.1.0",
+    "qunit": "^2.9.3",
+    "uglifyjs-webpack-plugin": "^2.2.0",
+    "webpack": "^4.41.2",
+    "webpack-cli": "^3.3.10",
     "grunt": "^1.0.4",
     "grunt-available-tasks": "^0.6.3",
     "grunt-bump": "^0.8.0",
@@ -59,4 +59,4 @@
     "grunt-release": "^0.14.0",
     "grunt-webpack": "^3.1.3"
   }
-}
+}

+ 9 - 6
qunit/qunit.html

@@ -1,16 +1,19 @@
 <!DOCTYPE html>
 <html>
+
 <head>
     <meta charset="utf-8">
     <title>Inputmask - QUnit</title>
     <link rel="stylesheet" href="../node_modules/qunit/qunit/qunit.css">
 </head>
+
 <body>
-<div id="qunit"></div>
-<div id="qunit-fixture"></div>
-²
-<script src="../node_modules/jquery/dist/jquery.js"></script>
-<script src="../node_modules/qunit/qunit/qunit.js"></script>
-<script src="../qunit/qunit.js" charset="utf-8"></script>
+    <div id="qunit"></div>
+    <div id="qunit-fixture"></div>
+
+    <script src="../node_modules/jquery/dist/jquery.js"></script>
+    <script src="../node_modules/qunit/qunit/qunit.js"></script>
+    <script src="../qunit/qunit.js" charset="utf-8"></script>
 </body>
+
 </html>

+ 36 - 0
qunit/tests_multi.js

@@ -441,4 +441,40 @@ export default function (qunit, Inputmask) {
 		assert.equal(testmask.inputmask._valueGet(), "123412341 23412341_", "Result " + testmask.inputmask._valueGet());
 
 	});
+
+	qunit.test("mask: option auto-chooses an option rather than denying input - type 3 - #2225", function (assert) {
+		var $fixture = $("#qunit-fixture");
+		$fixture.append("<input type=\"text\" id=\"testmask\" />");
+		var testmask = document.getElementById("testmask");
+		Inputmask({
+			mask: [
+				"4999 9999 9999 9999",
+				"5999 9999 9999 9999",
+				"2999 9999 9999 9999",
+				"6999 9999 9999 9999 [999]",
+				"3999 999999 99999"],
+			greedy: false,
+			keepStatic: false}).mask(testmask);
+		testmask.focus();
+		$("#testmask").Type("3");
+		assert.equal(testmask.inputmask._valueGet(), "3___ ______ _____", "Result " + testmask.inputmask._valueGet());
+	});
+
+	qunit.test("mask: option auto-chooses an option rather than denying input - type 1 - #2225", function (assert) {
+		var $fixture = $("#qunit-fixture");
+		$fixture.append("<input type=\"text\" id=\"testmask\" />");
+		var testmask = document.getElementById("testmask");
+		Inputmask({
+			mask: [
+				"4999 9999 9999 9999",
+				"5999 9999 9999 9999",
+				"2999 9999 9999 9999",
+				"6999 9999 9999 9999 [999]",
+				"3999 999999 99999"],
+			greedy: false,
+			keepStatic: false}).mask(testmask);
+		testmask.focus();
+		$("#testmask").Type("1");
+		assert.equal(testmask.inputmask._valueGet(), "", "Result " + testmask.inputmask._valueGet());
+	});
 };