Browse Source

Inputmask datetime alias mm/yy min value bug #2744

Robin Herbots 2 years ago
parent
commit
c9d28d2126

+ 1 - 0
Changelog.md

@@ -14,6 +14,7 @@
 - Enhance resolving of the ndxInitializer to determine the alternating tests.
 
 ### Fixed
+- Inputmask datetime alias mm/yy min value bug #2744
 - ALT codes #2779
 - Pressing the Win button #2780
 - d/mm/yyyy is converted to d/m//yyyd #2394

+ 1 - 1
bower.json

@@ -1,6 +1,6 @@
 {
   "name": "inputmask",
-  "version": "5.0.9-beta.55",
+  "version": "5.0.9-beta.56",
   "main": [
 	  "./index.js",
     "./css/inputmask.css"

+ 1 - 1
composer.json

@@ -1,7 +1,7 @@
 {
   "name": "robinherbots/inputmask",
   "description": "Inputmask is a javascript library which creates an input mask.  Inputmask can run against vanilla javascript, jQuery and jqlite.",
-  "version": "5.0.9-beta.55",
+  "version": "5.0.9-beta.56",
   "type": "library",
   "keywords": ["jquery", "plugins", "input", "form", "inputmask", "mask"],
   "homepage": "http://robinherbots.github.io/Inputmask",

+ 0 - 26
dist/bindings/inputmask.binding.js

@@ -1,26 +0,0 @@
-/*
- Input Mask plugin binding
- http://github.com/RobinHerbots/jquery.inputmask
- Copyright (c) Robin Herbots
- Licensed under the MIT license
- */
-(function (factory) {
-	factory(jQuery, window.Inputmask, window);
-}
-(function ($, Inputmask, window) {
-	$(window.document).ajaxComplete(function (event, xmlHttpRequest, ajaxOptions) {
-		if ($.inArray("html", ajaxOptions.dataTypes) !== -1) {
-			$(".inputmask, [data-inputmask], [data-inputmask-mask], [data-inputmask-alias], [data-inputmask-regex]").each(function (ndx, lmnt) {
-				if (lmnt.inputmask === undefined) {
-					Inputmask().mask(lmnt);
-				}
-			});
-		}
-	}).ready(function () {
-		$(".inputmask, [data-inputmask], [data-inputmask-mask], [data-inputmask-alias],[data-inputmask-regex]").each(function (ndx, lmnt) {
-			if (lmnt.inputmask === undefined) {
-				Inputmask().mask(lmnt);
-			}
-		});
-	});
-}));

+ 0 - 65
dist/colormask.css

@@ -1,65 +0,0 @@
-mark.im-caret {
-    animation: 1s blink step-end infinite !important;
-}
-
-mark.im-caret-select {
-    background-color: rgba(0, 0, 0, 0.25);
-}
-
-@keyframes blink {
-    from, to {
-        border-right-color: black;
-    }
-    50% {
-        /*border-right-color: transparent;*/
-        border-right-color: white;
-    }
-}
-
-span.im-static {
-    color: grey;
-}
-
-div.im-colormask {
-    display: inline-block;
-    border-style: groove;
-    border-width: 1px;
-    appearance: textfield;
-    cursor: text;
-}
-
-div.im-colormask > input, div.im-colormask > input:-webkit-autofill {
-    position: absolute !important;
-    display: inline-block;
-    background-color: transparent;
-    color: transparent;
-    -webkit-text-fill-color: transparent;
-    transition: background-color 5000s ease-in-out 0s;
-    caret-color: transparent;
-    text-shadow: none;
-    appearance: textfield;
-    border-style: none;
-    left: 0; /*calculated*/
-}
-
-div.im-colormask > input:focus {
-    outline: none;
-}
-
-div.im-colormask > input::selection {
-    background: none;
-}
-
-div.im-colormask > input::-moz-selection {
-    background: none;
-}
-
-div.im-colormask > input:-webkit-autofill ~ div {
-    background-color: rgb(255, 255, 255);
-}
-
-div.im-colormask > div {
-    color: black;
-    display: inline-block;
-    width: 100px; /*calculated*/
-}

File diff suppressed because it is too large
+ 0 - 3882
dist/colormask.js


File diff suppressed because it is too large
+ 0 - 8
dist/colormask.min.js


+ 0 - 5
dist/inputmask.es6.js

@@ -1,5 +0,0 @@
-import "./inputmask.js";
-
-const inputmask = window.Inputmask;
-window.Inputmask = undefined;
-export default inputmask;

File diff suppressed because it is too large
+ 0 - 3768
dist/inputmask.js


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


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


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


+ 9 - 6
lib/extensions/inputmask.date.extensions.js

@@ -99,7 +99,7 @@ class DateObject {
 			if (targetProp === "month") useDateObject = true;
 			if (targetProp === "year") {
 				useDateObject = true;
-				if (datavalue.length < 4) datavalue = pad(datavalue, 4, true);
+				if (datavalue.length < formatCode[fcode][4]) datavalue = pad(datavalue, formatCode[fcode][4], true);
 			}
 			if ((datavalue !== "" && !isNaN(datavalue)) || targetProp === "ampm") dateOperation.call(dateObj._date, datavalue);
 		}
@@ -151,12 +151,15 @@ let currentYear = new Date().getFullYear(), i18n = Inputmask.prototype.i18n, use
 		}, "month", function () {
 			return i18n.monthNames.slice(12, 24)[Date.prototype.getMonth.call(this)];
 		}], //Month as its full name.
-		yy: ["[0-9]{2}", Date.prototype.setFullYear, "year", function () {
+		yy: ["[0-9]{2}", function (val) {
+			const centuryPart = new Date().getFullYear().toString().slice(0, 2);
+			Date.prototype.setFullYear.call(this, `${centuryPart}${val}`);
+		}, "year", function () {
 			return pad(Date.prototype.getFullYear.call(this), 2);
-		}], //Year as last two digits; leading zero for years less than 10.
+		}, 2], //Year as last two digits; leading zero for years less than 10.
 		yyyy: ["[0-9]{4}", Date.prototype.setFullYear, "year", function () {
 			return pad(Date.prototype.getFullYear.call(this), 4);
-		}], h: ["[1-9]|1[0-2]", Date.prototype.setHours, "hours", Date.prototype.getHours], //Hours; no leading zero for single-digit hours (12-hour clock).
+		}, 4], h: ["[1-9]|1[0-2]", Date.prototype.setHours, "hours", Date.prototype.getHours], //Hours; no leading zero for single-digit hours (12-hour clock).
 		hh: ["0[1-9]|1[0-2]", Date.prototype.setHours, "hours", function () {
 			return pad(Date.prototype.getHours.call(this), 2);
 		}], //Hours; leading zero for single-digit hours (12-hour clock).
@@ -324,7 +327,7 @@ function isDateInRange(dateParts, result, opts, maskset, fromCheckval) {
 					if (fcode[3]) {
 						var setFn = fcode[1];
 						var current = dateParts[fcode[2]], minVal = opts.min[fcode[2]],
-							maxVal = opts.max ? opts.max[fcode[2]] : minVal, curVal = [];
+							maxVal = opts.max ? opts.max[fcode[2]] : minVal + 1, curVal = [];
 
 						let forceCurrentValue = false;
 						for (let i = 0; i < minVal.length; i++) {
@@ -402,7 +405,7 @@ function parse(format, dateObjValue, opts, raw) {
 		}
 		ndx++;
 	}
-	if (dateObjValue === undefined && (opts.placeholder === "" || opts.inputFormat.indexOf("mmmm") != -1)) {
+	if (dateObjValue === undefined && (opts.placeholder === "" || opts.inputFormat.indexOf("mmmm") !== -1)) {
 		opts.placeholder = placeHolder;
 	}
 	return mask;

+ 8 - 8
package-lock.json

@@ -1,12 +1,12 @@
 {
   "name": "inputmask",
-  "version": "5.0.9-beta.50",
+  "version": "5.0.9-beta.55",
   "lockfileVersion": 2,
   "requires": true,
   "packages": {
     "": {
       "name": "inputmask",
-      "version": "5.0.9-beta.50",
+      "version": "5.0.9-beta.55",
       "license": "MIT",
       "devDependencies": {
         "@babel/core": "^7.23.2",
@@ -4245,9 +4245,9 @@
       "dev": true
     },
     "node_modules/follow-redirects": {
-      "version": "1.14.8",
-      "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.8.tgz",
-      "integrity": "sha512-1x0S9UVJHsQprFcEC/qnNzBLcIxsjAV905f/UkQxbclCsoTWlacCNOpQa/anodLl2uaEKFhfWOvM2Qg77+15zA==",
+      "version": "1.15.6",
+      "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz",
+      "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==",
       "dev": true,
       "funding": [
         {
@@ -11040,9 +11040,9 @@
       "dev": true
     },
     "follow-redirects": {
-      "version": "1.14.8",
-      "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.8.tgz",
-      "integrity": "sha512-1x0S9UVJHsQprFcEC/qnNzBLcIxsjAV905f/UkQxbclCsoTWlacCNOpQa/anodLl2uaEKFhfWOvM2Qg77+15zA==",
+      "version": "1.15.6",
+      "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz",
+      "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==",
       "dev": true
     },
     "for-in": {

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "inputmask",
-  "version": "5.0.9-beta.55",
+  "version": "5.0.9-beta.56",
   "description": "Inputmask is a javascript library which creates an input mask.  Inputmask can run against vanilla javascript, jQuery and jqlite.",
   "main": "dist/inputmask.js",
   "exports": {

+ 27 - 0
qunit/tests_date.js

@@ -1369,4 +1369,31 @@ export default function (qunit, Inputmask) {
 		$("#testmask").Type("feb292024");
 		assert.equal(testmask.value, "Feb 29 2024", "Result " + testmask.value);
 	});
+
+	qunit.test("mm/yy + min/max - 09 - #2744", function (assert) {
+		var $fixture = $("#qunit-fixture");
+		$fixture.append("<input type=\"text\" id=\"testmask\" />");
+		var testmask = document.getElementById("testmask");
+		Inputmask("datetime", {
+			inputFormat: "mm/yy",
+			min: "10/23",
+			max: "10/33",
+		}).mask(testmask);
+		testmask.focus();
+		$("#testmask").Type("09");
+		assert.equal(testmask.value, "09/yy", "Result " + testmask.value);
+	});
+	qunit.test("mm/yy + min/max - 0924 - #2744", function (assert) {
+		var $fixture = $("#qunit-fixture");
+		$fixture.append("<input type=\"text\" id=\"testmask\" />");
+		var testmask = document.getElementById("testmask");
+		Inputmask("datetime", {
+			inputFormat: "mm/yy",
+			min: "10/23",
+			max: "10/33",
+		}).mask(testmask);
+		testmask.focus();
+		$("#testmask").Type("0924");
+		assert.equal(testmask.value, "09/24", "Result " + testmask.value);
+	});
 }