Robin Herbots 10 years ago
parent
commit
074c4c1721

+ 1 - 0
CHANGELOG.md

@@ -20,6 +20,7 @@ All notable changes to this project will be documented in this file.
 - Update placeholder handling
 
 ### Fixed
+- Escape value is inconsistent after mask #935
 - Escape optional marker, quantifiable marker, alternator marker and backslash not working #930
 - Is numeric carret position broken? #928
 - Decimal looses digits #924

+ 2 - 0
README.md

@@ -462,6 +462,8 @@ With the non-greedy option set to false, you can specify * as repeat.  This make
 ### autoUnmask
 Automatically unmask the value when retrieved.<br>Default: false.
 
+When setting this option to true the plugin also expects the initial value from the server to be unmasked.
+
 ### removeMaskOnSubmit
 Remove the mask before submitting the form.<br>Default: false
 

+ 1 - 1
bower.json

@@ -1,6 +1,6 @@
 {
   "name": "jquery.inputmask",
-  "version": "3.1.64-77",
+  "version": "3.1.64-84",
   "main": [
     "./dist/inputmask/jquery.inputmask.js",
     "./dist/inputmask/inputmask.js",

+ 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.1.64-77",
+    "version": "3.1.64-84",
     "keywords": [ "jquery", "plugins", "input", "form", "inputmask", "mask" ],
     "main": "./dist/jquery.inputmask.bundle.js",
     "scripts": [

+ 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.1.64-77",
+	"version": "3.1.64-84",
     "type": "library",
     "keywords": ["jquery", "plugins", "input", "form", "inputmask", "mask"],
     "homepage": "http://robinherbots.github.io/jquery.inputmask",

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

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.1.64-77
+* Version: 3.1.64-84
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "./inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery"), require("./inputmask")) : factory(jQuery);
@@ -456,6 +456,29 @@
             leapday: "donotuse",
             separator: "/",
             alias: "mm/dd/yyyy"
+        },
+        shamsi: {
+            regex: {
+                val2pre: function(separator) {
+                    var escapedSeparator = inputmask.escapeRegex.call(this, separator);
+                    return new RegExp("((0[1-9]|1[012])" + escapedSeparator + "[0-3])");
+                },
+                val2: function(separator) {
+                    var escapedSeparator = inputmask.escapeRegex.call(this, separator);
+                    return new RegExp("((0[1-9]|1[012])" + escapedSeparator + "(0[1-9]|[12][0-9]))|((0[1-9]|1[012])" + escapedSeparator + "30)|((0[1-6])" + escapedSeparator + "31)");
+                },
+                val1pre: new RegExp("[01]"),
+                val1: new RegExp("0[1-9]|1[012]")
+            },
+            yearrange: {
+                minyear: 1300,
+                maxyear: 1499
+            },
+            mask: "y/1/2",
+            leapday: "/12/30",
+            placeholder: "yyyy/mm/dd",
+            alias: "mm/dd/yyyy",
+            clearIncomplete: !0
         }
     }), inputmask;
 });

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


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

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

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


+ 5 - 8
dist/inputmask/inputmask.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.1.64-77
+* Version: 3.1.64-84
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery")) : factory(jQuery);
@@ -651,25 +651,22 @@
             }
             var inputValue = void 0 != nptvl ? nptvl.slice() : input._valueGet().split(""), charCodes = "", initialNdx = 0;
             if (resetMaskSet(), getMaskSet().p = seekNext(-1), writeOut && input._valueSet(""), 
-            !strict) {
-                var staticInput = getBufferTemplate().slice(0, seekNext(-1)).join(""), matches = inputValue.join("").match(new RegExp("^" + escapeRegex(staticInput), "g"));
+            !strict) if (1 != opts.autoUnmask) {
+                var staticInput = getBufferTemplate().slice(0, seekNext(-1)).join(""), matches = inputValue.join("").match(new RegExp("^" + inputmask.escapeRegex(staticInput), "g"));
                 matches && matches.length > 0 && (inputValue.splice(0, matches.length * staticInput.length), 
                 initialNdx = seekNext(initialNdx));
-            }
+            } else initialNdx = seekNext(initialNdx);
             $.each(inputValue, function(ndx, charCode) {
                 var keypress = $.Event("keypress");
                 keypress.which = charCode.charCodeAt(0), charCodes += charCode;
                 var lvp = getLastValidPosition(void 0, !0), lvTest = getMaskSet().validPositions[lvp], nextTest = getTestTemplate(lvp + 1, lvTest ? lvTest.locator.slice() : void 0, lvp);
-                if (!isTemplateMatch() || strict) {
+                if (!isTemplateMatch() || strict || opts.autoUnmask && -1 == lvp) {
                     var pos = strict ? ndx : null == nextTest.match.fn && nextTest.match.optionality && lvp + 1 < getMaskSet().p ? lvp + 1 : getMaskSet().p;
                     keypressEvent.call(input, keypress, !0, !1, strict, pos), initialNdx = pos + 1, 
                     charCodes = "";
                 } else keypressEvent.call(input, keypress, !0, !1, !0, lvp + 1);
             }), writeOut && writeBuffer(input, getBuffer(), $(input).is(":focus") ? seekNext(getLastValidPosition(0)) : void 0, $.Event("checkval"));
         }
-        function escapeRegex(str) {
-            return inputmask.escapeRegex(str);
-        }
         function unmaskedvalue($input) {
             if ($input[0].inputmask && !$input.hasClass("hasDatepicker")) {
                 var umValue = [], vps = getMaskSet().validPositions;

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


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

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

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


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

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

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


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

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

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


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

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

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


+ 28 - 8
dist/jquery.inputmask.bundle.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.1.64-77
+* Version: 3.1.64-84
 */
 !function($) {
     function inputmask(options) {
@@ -649,25 +649,22 @@
             }
             var inputValue = void 0 != nptvl ? nptvl.slice() : input._valueGet().split(""), charCodes = "", initialNdx = 0;
             if (resetMaskSet(), getMaskSet().p = seekNext(-1), writeOut && input._valueSet(""), 
-            !strict) {
-                var staticInput = getBufferTemplate().slice(0, seekNext(-1)).join(""), matches = inputValue.join("").match(new RegExp("^" + escapeRegex(staticInput), "g"));
+            !strict) if (1 != opts.autoUnmask) {
+                var staticInput = getBufferTemplate().slice(0, seekNext(-1)).join(""), matches = inputValue.join("").match(new RegExp("^" + inputmask.escapeRegex(staticInput), "g"));
                 matches && matches.length > 0 && (inputValue.splice(0, matches.length * staticInput.length), 
                 initialNdx = seekNext(initialNdx));
-            }
+            } else initialNdx = seekNext(initialNdx);
             $.each(inputValue, function(ndx, charCode) {
                 var keypress = $.Event("keypress");
                 keypress.which = charCode.charCodeAt(0), charCodes += charCode;
                 var lvp = getLastValidPosition(void 0, !0), lvTest = getMaskSet().validPositions[lvp], nextTest = getTestTemplate(lvp + 1, lvTest ? lvTest.locator.slice() : void 0, lvp);
-                if (!isTemplateMatch() || strict) {
+                if (!isTemplateMatch() || strict || opts.autoUnmask && -1 == lvp) {
                     var pos = strict ? ndx : null == nextTest.match.fn && nextTest.match.optionality && lvp + 1 < getMaskSet().p ? lvp + 1 : getMaskSet().p;
                     keypressEvent.call(input, keypress, !0, !1, strict, pos), initialNdx = pos + 1, 
                     charCodes = "";
                 } else keypressEvent.call(input, keypress, !0, !1, !0, lvp + 1);
             }), writeOut && writeBuffer(input, getBuffer(), $(input).is(":focus") ? seekNext(getLastValidPosition(0)) : void 0, $.Event("checkval"));
         }
-        function escapeRegex(str) {
-            return inputmask.escapeRegex(str);
-        }
         function unmaskedvalue($input) {
             if ($input[0].inputmask && !$input.hasClass("hasDatepicker")) {
                 var umValue = [], vps = getMaskSet().validPositions;
@@ -1849,6 +1846,29 @@
             leapday: "donotuse",
             separator: "/",
             alias: "mm/dd/yyyy"
+        },
+        shamsi: {
+            regex: {
+                val2pre: function(separator) {
+                    var escapedSeparator = inputmask.escapeRegex.call(this, separator);
+                    return new RegExp("((0[1-9]|1[012])" + escapedSeparator + "[0-3])");
+                },
+                val2: function(separator) {
+                    var escapedSeparator = inputmask.escapeRegex.call(this, separator);
+                    return new RegExp("((0[1-9]|1[012])" + escapedSeparator + "(0[1-9]|[12][0-9]))|((0[1-9]|1[012])" + escapedSeparator + "30)|((0[1-6])" + escapedSeparator + "31)");
+                },
+                val1pre: new RegExp("[01]"),
+                val1: new RegExp("0[1-9]|1[012]")
+            },
+            yearrange: {
+                minyear: 1300,
+                maxyear: 1499
+            },
+            mask: "y/1/2",
+            leapday: "/12/30",
+            placeholder: "yyyy/mm/dd",
+            alias: "mm/dd/yyyy",
+            clearIncomplete: !0
         }
     }), inputmask;
 }(jQuery), function($) {

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


+ 9 - 9
js/inputmask.js

@@ -1530,10 +1530,14 @@
 			if (writeOut) input._valueSet(""); //initial clear
 
 			if (!strict) {
-				var staticInput = getBufferTemplate().slice(0, seekNext(-1)).join(''),
-					matches = inputValue.join('').match(new RegExp("^" + escapeRegex(staticInput), "g"));
-				if (matches && matches.length > 0) {
-					inputValue.splice(0, matches.length * staticInput.length);
+				if (opts.autoUnmask != true) {
+					var staticInput = getBufferTemplate().slice(0, seekNext(-1)).join(''),
+						matches = inputValue.join('').match(new RegExp("^" + inputmask.escapeRegex(staticInput), "g"));
+					if (matches && matches.length > 0) {
+						inputValue.splice(0, matches.length * staticInput.length);
+						initialNdx = seekNext(initialNdx);
+					}
+				} else {
 					initialNdx = seekNext(initialNdx);
 				}
 			}
@@ -1546,7 +1550,7 @@
 				var lvp = getLastValidPosition(undefined, true),
 					lvTest = getMaskSet()["validPositions"][lvp],
 					nextTest = getTestTemplate(lvp + 1, lvTest ? lvTest.locator.slice() : undefined, lvp);
-				if (!isTemplateMatch() || strict) {
+				if (!isTemplateMatch() || strict || (opts.autoUnmask && lvp == -1)) {
 					var pos = strict ? ndx : (nextTest["match"].fn == null && nextTest["match"].optionality && (lvp + 1) < getMaskSet()["p"] ? lvp + 1 : getMaskSet()["p"]);
 					keypressEvent.call(input, keypress, true, false, strict, pos);
 					initialNdx = pos + 1;
@@ -1561,10 +1565,6 @@
 			}
 		}
 
-		function escapeRegex(str) {
-			return inputmask.escapeRegex(str);
-		}
-
 		function unmaskedvalue($input) {
 			if ($input[0].inputmask && !$input.hasClass('hasDatepicker')) {
 				var umValue = [],

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "jquery.inputmask",
-  "version": "3.1.64-77",
+  "version": "3.1.64-84",
   "description": "jquery.inputmask is a jquery plugin which create an input mask.",
   "main": "./dist/inputmask/jquery.inputmask.js",
   "files": [

+ 70 - 55
qunit/tests_escape.js

@@ -1,86 +1,101 @@
 module("Escape character");
 
-test("inputmask(\"9\\|9\")", function () {
-    var $fixture = $("#qunit-fixture");
-    $fixture.append('<input type="text" id="testmask" />');
-    var input = $("#testmask");
-    input.inputmask("9\\|9");
+test("inputmask(\"9\\|9\")", function() {
+	var $fixture = $("#qunit-fixture");
+	$fixture.append('<input type="text" id="testmask" />');
+	var input = $("#testmask");
+	input.inputmask("9\\|9");
 
-    input[0].focus();
+	input[0].focus();
 
-    input.Type("23");
-    equal(input.val(), "2|3", "Result " + input.val());
+	input.Type("23");
+	equal(input.val(), "2|3", "Result " + input.val());
 
-    input.remove();
+	input.remove();
 });
 
-test("inputmask(\"9\\[9\\]\")", function () {
-    var $fixture = $("#qunit-fixture");
-    $fixture.append('<input type="text" id="testmask" />');
-    var input = $("#testmask");
-    input.inputmask("9\\[9\\]");
+test("inputmask(\"9\\[9\\]\")", function() {
+	var $fixture = $("#qunit-fixture");
+	$fixture.append('<input type="text" id="testmask" />');
+	var input = $("#testmask");
+	input.inputmask("9\\[9\\]");
 
-    input[0].focus();
+	input[0].focus();
 
-    input.Type("23");
-    equal(input.val(), "2[3]", "Result " + input.val());
+	input.Type("23");
+	equal(input.val(), "2[3]", "Result " + input.val());
 
-    input.remove();
+	input.remove();
 });
 
-test("inputmask(\"9\\\\9\")", function () {
-    var $fixture = $("#qunit-fixture");
-    $fixture.append('<input type="text" id="testmask" />');
-    var input = $("#testmask");
-    input.inputmask("9\\\\9");
+test("inputmask(\"9\\\\9\")", function() {
+	var $fixture = $("#qunit-fixture");
+	$fixture.append('<input type="text" id="testmask" />');
+	var input = $("#testmask");
+	input.inputmask("9\\\\9");
 
-    input[0].focus();
+	input[0].focus();
 
-    input.Type("23");
-    equal(input.val(), "2\\3", "Result " + input.val());
+	input.Type("23");
+	equal(input.val(), "2\\3", "Result " + input.val());
 
-    input.remove();
+	input.remove();
 });
 
-test("inputmask(\"9\\{9\\}\")", function () {
-    var $fixture = $("#qunit-fixture");
-    $fixture.append('<input type="text" id="testmask" />');
-    var input = $("#testmask");
-    input.inputmask("9\\{9\\}");
+test("inputmask(\"9\\{9\\}\")", function() {
+	var $fixture = $("#qunit-fixture");
+	$fixture.append('<input type="text" id="testmask" />');
+	var input = $("#testmask");
+	input.inputmask("9\\{9\\}");
 
-    input[0].focus();
+	input[0].focus();
 
-    input.Type("23");
-    equal(input.val(), "2{3}", "Result " + input.val());
+	input.Type("23");
+	equal(input.val(), "2{3}", "Result " + input.val());
 
-    input.remove();
+	input.remove();
 });
 
-test("inputmask(\"9\\(9\\)\")", function () {
-    var $fixture = $("#qunit-fixture");
-    $fixture.append('<input type="text" id="testmask" />');
-    var input = $("#testmask");
-    input.inputmask("9\\(9\\)");
+test("inputmask(\"9\\(9\\)\")", function() {
+	var $fixture = $("#qunit-fixture");
+	$fixture.append('<input type="text" id="testmask" />');
+	var input = $("#testmask");
+	input.inputmask("9\\(9\\)");
 
-    input[0].focus();
+	input[0].focus();
 
-    input.Type("23");
-    equal(input.val(), "2(3)", "Result " + input.val());
+	input.Type("23");
+	equal(input.val(), "2(3)", "Result " + input.val());
 
-    input.remove();
+	input.remove();
 });
 
 
-test("inputmask(\"9\\?9\")", function () {
-    var $fixture = $("#qunit-fixture");
-    $fixture.append('<input type="text" id="testmask" />');
-    var input = $("#testmask");
-    input.inputmask("9\\?9");
+test("inputmask(\"9\\?9\")", function() {
+	var $fixture = $("#qunit-fixture");
+	$fixture.append('<input type="text" id="testmask" />');
+	var input = $("#testmask");
+	input.inputmask("9\\?9");
 
-    input[0].focus();
+	input[0].focus();
 
-    input.Type("23");
-    equal(input.val(), "2?3", "Result " + input.val());
+	input.Type("23");
+	equal(input.val(), "2?3", "Result " + input.val());
 
-    input.remove();
-});
+	input.remove();
+});
+
+test("inputmask(\"\\9999\") value not mask", function() {
+	var $fixture = $("#qunit-fixture");
+	$fixture.append('<input type="text" value="999" id="testmask" />');
+	var input = $("#testmask");
+	input.inputmask("\\9999", {
+		autoUnmask: true
+	});
+
+	input[0].focus();
+
+	equal(input[0]._valueGet(), "9999", "Result " + input[0]._valueGet());
+
+	input.remove();
+});