Browse Source

add character substitution

Robin Herbots 4 years ago
parent
commit
debc434760

+ 4 - 0
CHANGELOG.md

@@ -3,6 +3,7 @@
 ## [5.0.7 - UNRELEASED]
 
 ### Addition
+- character substitution
 - extend definition options - #2524
   - optional
   - static
@@ -10,10 +11,13 @@
 - add casing definition option to the readme
 
 ### Updates
+- currency alias: add character substitution for the radixpoint
 - alias \\d to [0-9] in regex masks
 - clear masktemplate before submitting regardsless of the clearMaskOnLostFocus option
 
 ### Fixed
+- Cant type dot on iphone #2541
+- How can I replace the dot for comma while tipping? #2542
 - Issue with global Inputmask.prototype reference (easy fix) #2544
 - crash the input value #2529 - part 1
 - fix datetime with jitmasking - #2297

+ 9 - 0
README.md

@@ -1138,6 +1138,15 @@ Time to show html5 validation error on form submit.
 
 Default: 3000
 
+### substitutes
+Define character substitutes.
+```
+substitutes: {
+  ",": "."
+}
+```
+Default: {}
+
 ## General
 ### set a value and apply the mask
 this can be done with the traditional jquery.val function (all browsers) or JavaScript value property for browsers which implement lookupGetter or getOwnPropertyDescriptor

+ 1 - 1
bower.json

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

+ 7 - 5
dist/inputmask.js

@@ -3,7 +3,7 @@
  * https://github.com/RobinHerbots/Inputmask
  * Copyright (c) 2010 - 2021 Robin Herbots
  * Licensed under the MIT license
- * Version: 5.0.7-beta.17
+ * Version: 5.0.7-beta.18
  */
 !function(e, t) {
     if ("object" == typeof exports && "object" == typeof module) module.exports = t(); else if ("function" == typeof define && define.amd) define([], t); else {
@@ -86,7 +86,8 @@
                     importDataAttributes: !0,
                     shiftPositions: !0,
                     usePrototypeDefinitions: !0,
-                    validationEventTimeOut: 3e3
+                    validationEventTimeOut: 3e3,
+                    substitutes: {}
                 };
                 t.default = r;
             },
@@ -363,7 +364,7 @@
                         t.ignorable = i.ignorables.includes(p);
                     },
                     keypressEvent: function(e, t, i, a, o) {
-                        var u = this.inputmask || this, c = u.opts, f = u.dependencyLib, d = u.maskset, p = u.el, v = f(p), h = e.which || e.charCode || e.keyCode;
+                        var u = this.inputmask || this, c = u.opts, f = u.dependencyLib, d = u.maskset, p = u.el, v = f(p), h = e.keyCode;
                         if (!(!0 === t || e.ctrlKey && e.altKey) && (e.ctrlKey || e.metaKey || u.ignorable)) return h === r.default.ENTER && u.undoValue !== u._valueGet(!0) && (u.undoValue = u._valueGet(!0), 
                         setTimeout((function() {
                             v.trigger("change");
@@ -374,7 +375,7 @@
                                 begin: o,
                                 end: o
                             } : n.caret.call(u, p), k = String.fromCharCode(h);
-                            d.writeOutBuffer = !0;
+                            k = c.substitutes[k] || k, d.writeOutBuffer = !0;
                             var y = s.isValid.call(u, g, k, a, void 0, void 0, void 0, t);
                             if (!1 !== y && (n.resetMaskSet.call(u, !0), m = void 0 !== y.caret ? y.caret : n.seekNext.call(u, y.pos.begin ? y.pos.begin : y.pos), 
                             d.p = m), m = c.numericInput && void 0 === y.caret ? n.seekPrevious.call(u, m) : m, 
@@ -1168,7 +1169,8 @@
                                 null !== e.max && (e.max = e.max.toString().replace(new RegExp((0, r.default)(e.groupSeparator), "g"), ""), 
                                 "," === e.radixPoint && (e.max = e.max.replace(e.radixPoint, ".")), e.max = isFinite(e.max) ? parseFloat(e.max) : NaN, 
                                 isNaN(e.max) && (e.max = Number.MAX_VALUE)), e.parseMinMaxOptions = "done");
-                            }(e), n;
+                            }(e), "" !== e.radixPoint && (e.substitutes["." == e.radixPoint ? "," : "."] = e.radixPoint), 
+                            n;
                         },
                         _mask: function(e) {
                             return "(" + e.groupSeparator + "999){+|1}";

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


+ 7 - 5
dist/jquery.inputmask.js

@@ -3,7 +3,7 @@
  * https://github.com/RobinHerbots/Inputmask
  * Copyright (c) 2010 - 2021 Robin Herbots
  * Licensed under the MIT license
- * Version: 5.0.7-beta.17
+ * Version: 5.0.7-beta.18
  */
 !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 {
@@ -96,7 +96,8 @@
                     importDataAttributes: !0,
                     shiftPositions: !0,
                     usePrototypeDefinitions: !0,
-                    validationEventTimeOut: 3e3
+                    validationEventTimeOut: 3e3,
+                    substitutes: {}
                 };
                 t.default = r;
             },
@@ -237,7 +238,7 @@
                         t.ignorable = i.ignorables.includes(p);
                     },
                     keypressEvent: function(e, t, i, a, o) {
-                        var u = this.inputmask || this, c = u.opts, f = u.dependencyLib, d = u.maskset, p = u.el, h = f(p), v = e.which || e.charCode || e.keyCode;
+                        var u = this.inputmask || this, c = u.opts, f = u.dependencyLib, d = u.maskset, p = u.el, h = f(p), v = e.keyCode;
                         if (!(!0 === t || e.ctrlKey && e.altKey) && (e.ctrlKey || e.metaKey || u.ignorable)) return v === r.default.ENTER && u.undoValue !== u._valueGet(!0) && (u.undoValue = u._valueGet(!0), 
                         setTimeout((function() {
                             h.trigger("change");
@@ -248,7 +249,7 @@
                                 begin: o,
                                 end: o
                             } : n.caret.call(u, p), k = String.fromCharCode(v);
-                            d.writeOutBuffer = !0;
+                            k = c.substitutes[k] || k, d.writeOutBuffer = !0;
                             var y = s.isValid.call(u, g, k, a, void 0, void 0, void 0, t);
                             if (!1 !== y && (n.resetMaskSet.call(u, !0), m = void 0 !== y.caret ? y.caret : n.seekNext.call(u, y.pos.begin ? y.pos.begin : y.pos), 
                             d.p = m), m = c.numericInput && void 0 === y.caret ? n.seekPrevious.call(u, m) : m, 
@@ -1042,7 +1043,8 @@
                                 null !== e.max && (e.max = e.max.toString().replace(new RegExp((0, r.default)(e.groupSeparator), "g"), ""), 
                                 "," === e.radixPoint && (e.max = e.max.replace(e.radixPoint, ".")), e.max = isFinite(e.max) ? parseFloat(e.max) : NaN, 
                                 isNaN(e.max) && (e.max = Number.MAX_VALUE)), e.parseMinMaxOptions = "done");
-                            }(e), n;
+                            }(e), "" !== e.radixPoint && (e.substitutes["." == e.radixPoint ? "," : "."] = e.radixPoint), 
+                            n;
                         },
                         _mask: function(e) {
                             return "(" + e.groupSeparator + "999){+|1}";

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


+ 2 - 1
lib/defaults.js

@@ -96,5 +96,6 @@ export default {
 	importDataAttributes: true, //import data-inputmask attributes
 	shiftPositions: true, //shift position of the mask entries on entry and deletion.
 	usePrototypeDefinitions: true, //use the default defined definitions from the prototype
-	validationEventTimeOut: 3000 //Time to show validation error on form submit
+	validationEventTimeOut: 3000, //Time to show validation error on form submit
+	substitutes: {} //define character substitutes
 };

+ 3 - 1
lib/eventhandlers.js

@@ -97,7 +97,7 @@ var EventHandlers = {
 
 		var input = inputmask.el,
 			$input = $(input),
-			k = e.which || e.charCode || e.keyCode;
+			k = e.keyCode;
 
 		if (checkval !== true && (!(e.ctrlKey && e.altKey) && (e.ctrlKey || e.metaKey || inputmask.ignorable))) {
 			if (k === keyCode.ENTER && inputmask.undoValue !== inputmask._valueGet(true)) {
@@ -118,6 +118,8 @@ var EventHandlers = {
 				} : caret.call(inputmask, input),
 				forwardPosition, c = String.fromCharCode(k);
 
+			//allow for character substitution
+			c = opts.substitutes[c] || c;
 			maskset.writeOutBuffer = true;
 			var valResult = isValid.call(inputmask, pos, c, strict, undefined, undefined, undefined, checkval);
 			if (valResult !== false) {

+ 2 - 1
lib/extensions/inputmask.numeric.extensions.js

@@ -194,7 +194,8 @@ function genMask(opts) {
 	opts.greedy = false; //enforce greedy false
 
 	parseMinMaxOptions(opts);
-
+	if (opts.radixPoint !== "")
+		opts.substitutes[opts.radixPoint == "." ? "," : "."] = opts.radixPoint;
 	// console.log(mask);
 	return mask;
 }

+ 1 - 1
package.json

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