Browse Source

Unmasked value stopped working in version 5.0.9 fix #2800

Robin Herbots 1 year ago
parent
commit
a85078d849

+ 1 - 0
Changelog.md

@@ -7,6 +7,7 @@
 ### Updates
 
 ### Fixed
+- Unmasked value stopped working in version 5.0.9 #2800
 - Alias datetime + repeat bug #2806
 - The inputmask is autocompleted to the min value when deleting the radix point #2773
 

+ 1 - 1
bower.json

@@ -1,6 +1,6 @@
 {
   "name": "inputmask",
-  "version": "5.0.10-beta.2",
+  "version": "5.0.10-beta.3",
   "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.10-beta.2",
+  "version": "5.0.10-beta.3",
   "type": "library",
   "keywords": ["jquery", "plugins", "input", "form", "inputmask", "mask"],
   "homepage": "http://robinherbots.github.io/Inputmask",

+ 13 - 12
dist/colormask.js

@@ -3,7 +3,7 @@
  * https://github.com/RobinHerbots/Inputmask
  * Copyright (c) 2010 - 2024 Robin Herbots
  * Licensed under the MIT license
- * Version: 5.0.10-beta.2
+ * Version: 5.0.10-beta.3
  */
 !function(e, t) {
     if ("object" == typeof exports && "object" == typeof module) module.exports = t(); else if ("function" == typeof define && define.amd) define([], t); else {
@@ -1170,21 +1170,22 @@
                     }, {
                         key: "initDateObject",
                         value: function(e, t, n) {
-                            var i;
-                            for (P(t).lastIndex = 0; i = P(t).exec(this.format); ) {
-                                var a = /\d+$/.exec(i[0]), r = a ? i[0][0] + "x" : i[0], o = void 0;
+                            var i, a = -1;
+                            for (P(t).lastIndex = 0; i = P(t).exec(this.format); ) if (i.index >= a) {
+                                var r = /\d+$/.exec(i[0]), o = r ? i[0][0] + "x" : i[0], s = void 0;
                                 if (void 0 !== e) {
-                                    if (a) {
-                                        var s = P(t).lastIndex, c = j.call(n, i.index, t, n && n.maskset);
-                                        P(t).lastIndex = s, o = e.slice(0, e.indexOf(c.nextMatch[0]));
+                                    if (r) {
+                                        var c = P(t).lastIndex, u = j.call(n, i.index, t, n && n.maskset);
+                                        P(t).lastIndex = c, s = e.slice(0, e.indexOf(u.nextMatch[0]));
                                     } else {
-                                        for (var u = i[0][0], f = i.index; n && (t.placeholder[l.getTest.call(n, f).match.placeholder] || l.getTest.call(n, f).match.placeholder) === u; ) f++;
-                                        var p = f - i.index;
-                                        o = e.slice(0, p || y[r] && y[r][4] || r.length);
+                                        for (var f = i[0][0], p = i.index; n && (t.placeholder[l.getTest.call(n, p).match.placeholder] || l.getTest.call(n, p).match.placeholder) === f; ) p++;
+                                        a = p;
+                                        var d = p - i.index;
+                                        s = e.slice(0, d || y[o] && y[o][4] || o.length);
                                     }
-                                    e = e.slice(o.length);
+                                    e = e.slice(s.length);
                                 }
-                                Object.prototype.hasOwnProperty.call(y, r) && this.setValue(this, o, r, y[r][2], y[r][1]);
+                                Object.prototype.hasOwnProperty.call(y, o) && this.setValue(this, s, o, y[o][2], y[o][1]);
                             }
                         }
                     }, {

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


+ 13 - 12
dist/inputmask.js

@@ -3,7 +3,7 @@
  * https://github.com/RobinHerbots/Inputmask
  * Copyright (c) 2010 - 2024 Robin Herbots
  * Licensed under the MIT license
- * Version: 5.0.10-beta.2
+ * Version: 5.0.10-beta.3
  */
 !function(e, t) {
     if ("object" == typeof exports && "object" == typeof module) module.exports = t(); else if ("function" == typeof define && define.amd) define([], t); else {
@@ -1055,21 +1055,22 @@
                     }, {
                         key: "initDateObject",
                         value: function(e, t, n) {
-                            var i;
-                            for (P(t).lastIndex = 0; i = P(t).exec(this.format); ) {
-                                var a = /\d+$/.exec(i[0]), r = a ? i[0][0] + "x" : i[0], o = void 0;
+                            var i, a = -1;
+                            for (P(t).lastIndex = 0; i = P(t).exec(this.format); ) if (i.index >= a) {
+                                var r = /\d+$/.exec(i[0]), o = r ? i[0][0] + "x" : i[0], s = void 0;
                                 if (void 0 !== e) {
-                                    if (a) {
-                                        var s = P(t).lastIndex, c = j.call(n, i.index, t, n && n.maskset);
-                                        P(t).lastIndex = s, o = e.slice(0, e.indexOf(c.nextMatch[0]));
+                                    if (r) {
+                                        var c = P(t).lastIndex, u = j.call(n, i.index, t, n && n.maskset);
+                                        P(t).lastIndex = c, s = e.slice(0, e.indexOf(u.nextMatch[0]));
                                     } else {
-                                        for (var u = i[0][0], f = i.index; n && (t.placeholder[l.getTest.call(n, f).match.placeholder] || l.getTest.call(n, f).match.placeholder) === u; ) f++;
-                                        var p = f - i.index;
-                                        o = e.slice(0, p || y[r] && y[r][4] || r.length);
+                                        for (var f = i[0][0], p = i.index; n && (t.placeholder[l.getTest.call(n, p).match.placeholder] || l.getTest.call(n, p).match.placeholder) === f; ) p++;
+                                        a = p;
+                                        var d = p - i.index;
+                                        s = e.slice(0, d || y[o] && y[o][4] || o.length);
                                     }
-                                    e = e.slice(o.length);
+                                    e = e.slice(s.length);
                                 }
-                                Object.prototype.hasOwnProperty.call(y, r) && this.setValue(this, o, r, y[r][2], y[r][1]);
+                                Object.prototype.hasOwnProperty.call(y, o) && this.setValue(this, s, o, y[o][2], y[o][1]);
                             }
                         }
                     }, {

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


+ 13 - 12
dist/jquery.inputmask.js

@@ -3,7 +3,7 @@
  * https://github.com/RobinHerbots/Inputmask
  * Copyright (c) 2010 - 2024 Robin Herbots
  * Licensed under the MIT license
- * Version: 5.0.10-beta.2
+ * Version: 5.0.10-beta.3
  */
 !function(e, t) {
     if ("object" == typeof exports && "object" == typeof module) module.exports = t(require("jquery")); else if ("function" == typeof define && define.amd) define([ "jquery" ], t); else {
@@ -884,21 +884,22 @@
                     }, {
                         key: "initDateObject",
                         value: function(e, t, n) {
-                            var i;
-                            for (P(t).lastIndex = 0; i = P(t).exec(this.format); ) {
-                                var a = /\d+$/.exec(i[0]), r = a ? i[0][0] + "x" : i[0], o = void 0;
+                            var i, a = -1;
+                            for (P(t).lastIndex = 0; i = P(t).exec(this.format); ) if (i.index >= a) {
+                                var r = /\d+$/.exec(i[0]), o = r ? i[0][0] + "x" : i[0], l = void 0;
                                 if (void 0 !== e) {
-                                    if (a) {
-                                        var l = P(t).lastIndex, c = j.call(n, i.index, t, n && n.maskset);
-                                        P(t).lastIndex = l, o = e.slice(0, e.indexOf(c.nextMatch[0]));
+                                    if (r) {
+                                        var c = P(t).lastIndex, u = j.call(n, i.index, t, n && n.maskset);
+                                        P(t).lastIndex = c, l = e.slice(0, e.indexOf(u.nextMatch[0]));
                                     } else {
-                                        for (var u = i[0][0], f = i.index; n && (t.placeholder[s.getTest.call(n, f).match.placeholder] || s.getTest.call(n, f).match.placeholder) === u; ) f++;
-                                        var p = f - i.index;
-                                        o = e.slice(0, p || y[r] && y[r][4] || r.length);
+                                        for (var f = i[0][0], p = i.index; n && (t.placeholder[s.getTest.call(n, p).match.placeholder] || s.getTest.call(n, p).match.placeholder) === f; ) p++;
+                                        a = p;
+                                        var d = p - i.index;
+                                        l = e.slice(0, d || y[o] && y[o][4] || o.length);
                                     }
-                                    e = e.slice(o.length);
+                                    e = e.slice(l.length);
                                 }
-                                Object.prototype.hasOwnProperty.call(y, r) && this.setValue(this, o, r, y[r][2], y[r][1]);
+                                Object.prototype.hasOwnProperty.call(y, o) && this.setValue(this, l, o, y[o][2], y[o][1]);
                             }
                         }
                     }, {

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


+ 47 - 41
lib/extensions/inputmask.date.extensions.js

@@ -32,53 +32,59 @@ class DateObject {
   }
 
   initDateObject(mask, opts, inputmask) {
-    let match;
+    let match,
+      lastNdx = -1;
     getTokenizer(opts).lastIndex = 0;
     while ((match = getTokenizer(opts).exec(this.format))) {
-      let dynMatches = /\d+$/.exec(match[0]),
-        fcode = dynMatches ? match[0][0] + "x" : match[0],
-        value;
-      if (mask !== undefined) {
-        // console.log("mask", mask);
-        if (dynMatches) {
-          const lastIndex = getTokenizer(opts).lastIndex,
-            tokenMatch = getTokenMatch.call(
-              inputmask,
-              match.index,
-              opts,
-              inputmask && inputmask.maskset
+      if (match.index >= lastNdx) {
+        let dynMatches = /\d+$/.exec(match[0]),
+          fcode = dynMatches ? match[0][0] + "x" : match[0],
+          value;
+        if (mask !== undefined) {
+          // console.log("mask", mask);
+          if (dynMatches) {
+            const lastIndex = getTokenizer(opts).lastIndex,
+              tokenMatch = getTokenMatch.call(
+                inputmask,
+                match.index,
+                opts,
+                inputmask && inputmask.maskset
+              );
+            getTokenizer(opts).lastIndex = lastIndex;
+            value = mask.slice(0, mask.indexOf(tokenMatch.nextMatch[0]));
+          } else {
+            let targetSymbol = match[0][0],
+              ndx = match.index;
+            while (
+              inputmask &&
+              (opts.placeholder[
+                getTest.call(inputmask, ndx).match.placeholder
+              ] || getTest.call(inputmask, ndx).match.placeholder) ===
+                targetSymbol
+            ) {
+              ndx++;
+            }
+            lastNdx = ndx;
+            const targetMatchLength = ndx - match.index;
+            value = mask.slice(
+              0,
+              targetMatchLength ||
+                (formatCode[fcode] && formatCode[fcode][4]) ||
+                fcode.length
             );
-          getTokenizer(opts).lastIndex = lastIndex;
-          value = mask.slice(0, mask.indexOf(tokenMatch.nextMatch[0]));
-        } else {
-          let targetSymbol = match[0][0],
-            ndx = match.index;
-          while (
-            inputmask &&
-            (opts.placeholder[getTest.call(inputmask, ndx).match.placeholder] ||
-              getTest.call(inputmask, ndx).match.placeholder) === targetSymbol
-          ) {
-            ndx++;
           }
-          const targetMatchLength = ndx - match.index;
-          value = mask.slice(
-            0,
-            targetMatchLength ||
-              (formatCode[fcode] && formatCode[fcode][4]) ||
-              fcode.length
-          );
+          mask = mask.slice(value.length);
         }
-        mask = mask.slice(value.length);
-      }
 
-      if (Object.prototype.hasOwnProperty.call(formatCode, fcode)) {
-        this.setValue(
-          this,
-          value,
-          fcode,
-          formatCode[fcode][2],
-          formatCode[fcode][1]
-        );
+        if (Object.prototype.hasOwnProperty.call(formatCode, fcode)) {
+          this.setValue(
+            this,
+            value,
+            fcode,
+            formatCode[fcode][2],
+            formatCode[fcode][1]
+          );
+        }
       }
     }
   }

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "inputmask",
-  "version": "5.0.10-beta.2",
+  "version": "5.0.10-beta.3",
   "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": {