Browse Source

implement optional masks with greede false option - see readme

Robin Herbots 12 years ago
parent
commit
eadc0579e8

+ 10 - 0
README.md

@@ -316,6 +316,16 @@ While the field has focus and is blank, users will see the full mask `___-___`.
 When the required part of the mask is filled and the field loses focus, the user will see `123`.
 When both the required and optional parts of the mask are filled out and the field loses focus, the user will see `123-ABC`.
 
+#### Optional masks with greedy false
+
+When defining an optional mask together with the greedy: false option, the inputmask will show the smallest possible mask as input first.
+
+```javascript
+$(selector).inputmask({ mask: "99999[-9999]", greedy: false });
+```
+
+The initial mask shown will be "_____" instead of "_____-____". 
+
 ### Multiple masks
 
 You can define multiple mask for your input.  Depending on the input the masking will switch between the defined masks.  

+ 1 - 1
build.properties

@@ -7,7 +7,7 @@ distdir = dist
 
 build.major = 2
 build.minor = 3
-build.revision = 2
+build.revision = 4
 
 target = jquery.inputmask.bundle.js
 target.min = jquery.inputmask.bundle.min.js

+ 1 - 1
component.json

@@ -1,6 +1,6 @@
 {
     "name": "jquery.inputmask",
-    "version": "2.3.3",
+    "version": "2.3.4",
     "main": "./dist/jquery.inputmask.bundle.js",
     "dependencies": {
         "jquery": ">=1.5"

BIN
dist/jQuery.InputMask.2.3.3.nupkg


BIN
dist/jQuery.InputMask.2.3.4.nupkg


+ 6 - 6
dist/jquery.inputmask.bundle.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2013 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 2.3.3
+* Version: 2.3.4
 */
 
 (function ($) {
@@ -404,7 +404,7 @@
                     });
                 } else generateMask("", opts.mask.toString());
 
-                return ms;
+                return opts.greedy ? ms : ms.sort(function (a, b) { return a["mask"].length - b["mask"].length; });
             }
             function getPlaceHolder(pos) {
                 return opts.placeholder.charAt(pos % opts.placeholder.length);
@@ -1495,7 +1495,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2013 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 2.3.3
+Version: 2.3.4
 
 Optional extensions on the jquery.inputmask base
 */
@@ -1597,7 +1597,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2012 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 2.3.3
+Version: 2.3.4
 
 Optional extensions on the jquery.inputmask base
 */
@@ -2066,7 +2066,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2013 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 2.3.3
+Version: 2.3.4
 
 Optional extensions on the jquery.inputmask base
 */
@@ -2233,7 +2233,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2013 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 2.3.3
+Version: 2.3.4
 
 Regex extensions on the jquery.inputmask base
 Allows for using regular expressions as a mask

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


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


+ 1 - 1
jquery.inputmask.jquery.json

@@ -8,7 +8,7 @@
 		"inputmask",
 		"mask"
     ],
-    "version": "2.3.3",
+    "version": "2.3.4",
     "author": {
         "name": "Robin Herbots",
         "url": "http://github.com/RobinHerbots/jquery.inputmask"

+ 1 - 1
js/jquery.inputmask.js

@@ -404,7 +404,7 @@
                     });
                 } else generateMask("", opts.mask.toString());
 
-                return ms;
+                return opts.greedy ? ms : ms.sort(function (a, b) { return a["mask"].length - b["mask"].length; });
             }
             function getPlaceHolder(pos) {
                 return opts.placeholder.charAt(pos % opts.placeholder.length);

+ 58 - 3
qunit/tests.js

@@ -514,7 +514,7 @@ test("inputmask({ mask: [\"99999\", \"99999-9999\"]]}) - input 1234512", functio
     $("#testmask").remove();
 });
 
-test("inputmask({ mask: [\"99999\", \"99999-9999\"]]}) - input 1234561234", function () {
+test("inputmask({ mask: [\"99999\", \"99999-9999\", \"999999-9999\"]]}) - input 1234561234", function () {
     $('body').append('<input type="text" id="testmask" />');
     $("#testmask").inputmask({ mask: ["99999", "99999-9999", "999999-9999" ] });
 
@@ -524,14 +524,69 @@ test("inputmask({ mask: [\"99999\", \"99999-9999\"]]}) - input 1234561234", func
 
     $("#testmask").remove();
 });
-test("inputmask({ mask: [\"99999\", \"99999-9999\"]]}) - input 123456", function () {
+test("inputmask({ mask: [\"99999\", \"99999-9999\", \"999999-9999\"]]}) - input 123456", function () {
     $('body').append('<input type="text" id="testmask" />');
     $("#testmask").inputmask({ mask: ["99999", "99999-9999", "999999-9999"] });
 
     $("#testmask")[0].focus();
     $("#testmask").Type("123456");
     equal($("#testmask").val(), "12345-6___", "Result " + $("#testmask").val());
-    //this is correct as see sequence of the masks || currently "99999-9999", "999999-9999" are valid and thus showing "99999-9999"
+    //this is correct as the sequence of the masks || currently "99999-9999", "999999-9999" are valid and thus showing "99999-9999"
+
+    $("#testmask").remove();
+});
+
+test("inputmask({ mask: \"99999[-9999]\", greedy: true }) - input 123", function () {
+    $('body').append('<input type="text" id="testmask" />');
+    $("#testmask").inputmask({ mask: "99999[-9999]", greedy: true });
+
+    $("#testmask")[0].focus();
+    $("#testmask").Type("123");
+    equal($("#testmask").val(), "123__-____", "Result " + $("#testmask").val());
+
+    $("#testmask").remove();
+});
+
+test("inputmask({ mask: \"99999[-9999]\", greedy: false }) - input 123", function () {
+    $('body').append('<input type="text" id="testmask" />');
+    $("#testmask").inputmask({ mask: "99999[-9999]", greedy: false });
+
+    $("#testmask")[0].focus();
+    $("#testmask").Type("123");
+    equal($("#testmask").val(), "123__", "Result " + $("#testmask").val());
+
+    $("#testmask").remove();
+});
+
+test("inputmask({ mask: \"99999[-9999]\", greedy: false }) - input 12345", function () {
+    $('body').append('<input type="text" id="testmask" />');
+    $("#testmask").inputmask({ mask: "99999[-9999]", greedy: false });
+
+    $("#testmask")[0].focus();
+    $("#testmask").Type("12345");
+    equal($("#testmask").val(), "12345", "Result " + $("#testmask").val());
+
+    $("#testmask").remove();
+});
+
+test("inputmask({ mask: \"99999[-9999]\", greedy: false }) - input 123456", function () {
+    $('body').append('<input type="text" id="testmask" />');
+    $("#testmask").inputmask({ mask: "99999[-9999]", greedy: false });
+
+    $("#testmask")[0].focus();
+    $("#testmask").Type("123456");
+    equal($("#testmask").val(), "12345-6___", "Result " + $("#testmask").val());
+
+    $("#testmask").remove();
+});
+
+test("inputmask({ mask: \"99999[-9999]\", greedy: false }) - input 123456789", function () {
+    $('body').append('<input type="text" id="testmask" />');
+    $("#testmask").inputmask({ mask: "99999[-9999]", greedy: false });
+
+    $("#testmask")[0].focus();
+    $("#testmask").Type("123456789");
+    equal($("#testmask").val(), "12345-6789", "Result " + $("#testmask").val());
 
     $("#testmask").remove();
 });