ソースを参照

fix maxlength

Robin Herbots 11 年 前
コミット
1fe6c80fee

+ 33 - 34
README.md

@@ -141,7 +141,7 @@ TODO
 
 ### Multi masks
 
-In the current implemantation you need to include the jquery.inputmask-multi.js
+In the current implementation you need to include the jquery.inputmask-multi.js
 
 You can define multiple mask for your input.  Depending on the input the masking will switch between the defined masks.  
 This can be useful when the masks are too different to solve it with optional parts.
@@ -405,10 +405,41 @@ $(document).ready(function(){
    }});
 });
 ```
-
 #### showMaskOnFocus
+
+Shows the mask when the input gets focus. (default = true)
+
+```javascript
+$(document).ready(function(){
+    $("#ssn").inputmask("999-99-9999",{ showMaskOnFocus: true }); //default
+});
+```
+
+To make sure no mask is visible on focus also set the showMaskOnHover to false.  Otherwise hovering with the mouse will set the mask and will stay on focus.
+
 #### showMaskOnHover
+
+Shows the mask when hovering the mouse. (default = true)
+
+```javascript
+$(document).ready(function(){
+    $("#ssn").inputmask("999-99-9999",{ showMaskOnHover: true }); //default
+});
+```
+
 #### onKeyValidation
+
+Callback function is executed on every keyvalidation with the result as parameter.
+
+```javascript
+$(document).ready(function(){
+    $("#ssn").inputmask("999-99-9999",
+			{ onKeyValidation: function (result) {
+								console.log(result);
+								} });
+});
+```
+
 #### skipOptionalPartCharacter
 #### showTooltip
 
@@ -663,39 +694,7 @@ $(document).ready(function(){
    else validateValue(val); 
 });
 ```
-### showMaskOnFocus
-
-Shows the mask when the input gets focus. (default = true)
-
-```javascript
-$(document).ready(function(){
-    $("#ssn").inputmask("999-99-9999",{ showMaskOnFocus: true }); //default
-});
-```
-
-To make sure no mask is visible on focus also set the showMaskOnHover to false.  Otherwise hovering with the mouse will set the mask and will stay on focus.
 
-### showMaskOnHover
-
-Shows the mask when hovering the mouse. (default = true)
-
-```javascript
-$(document).ready(function(){
-    $("#ssn").inputmask("999-99-9999",{ showMaskOnHover: true }); //default
-});
-```
-### onKeyValidation
-
-Callback function is executed on every keyvalidation with the result as parameter.
-
-```javascript
-$(document).ready(function(){
-    $("#ssn").inputmask("999-99-9999",
-			{ onKeyValidation: function (result) {
-								console.log(result);
-								} });
-});
-```
 
 
 

+ 1 - 1
bower.json

@@ -1,6 +1,6 @@
 {
     "name": "jquery.inputmask",
-    "version": "3.0.33",
+    "version": "3.0.34",
     "main": "./dist/jquery.inputmask.bundle.js",
 	"keywords" : ["jQuery", "plugins", "input", "form", "inputmask", "mask"],
 	"description": "jquery.inputmask is a jquery plugin which create an input mask.",

+ 1 - 1
build.properties

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

BIN
dist/jQuery.InputMask.3.0.33.nupkg


BIN
dist/jQuery.InputMask.3.0.34.nupkg


+ 45 - 30
dist/jquery.inputmask.bundle.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2014 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.0.33
+* Version: 3.0.34
 */
 
 (function ($) {
@@ -586,12 +586,14 @@
                                     return false;//breakout if refreshFromBuffer && nothing to insert
                                 }
                                 validatedPos = rslt.pos != undefined ? rslt.pos : position;
-                                tst = getTests(validatedPos)[0]; //possible mismatch TODO
+                                if (validatedPos != position)
+                                    tst = getTests(validatedPos)[0]; //possible mismatch TODO
 
                             } else if (rslt !== true && rslt["pos"] != position) { //their is a position offset
                                 validatedPos = rslt["pos"];
                                 refreshFromBuffer(position, validatedPos);
-                                tst = getTests(validatedPos)[0]; //possible mismatch TODO
+                                if (validatedPos != position)
+                                    tst = getTests(validatedPos)[0]; //possible mismatch TODO
                             }
                             if (ndx > 0) {
                                 resetMaskSet(true);
@@ -606,6 +608,7 @@
                 }
 
                 var maskPos = pos;
+                if (maskPos >= getMaskLength()) return false;
                 var result = _isValid(maskPos, c, strict, fromSetValid);
                 if (!strict && result === false) {
                     var currentPosValid = getMaskSet()["validPositions"][maskPos];
@@ -1479,7 +1482,7 @@
                 insertMode: true, //insert the input or overwrite the input
                 clearIncomplete: false, //clear the incomplete input on blur
                 aliases: {}, //aliases definitions => see jquery.inputmask.extensions.js
-				alias: null,
+                alias: null,
                 onKeyUp: $.noop, //override to implement autocomplete on certain keys for example
                 onKeyDown: $.noop, //override to implement autocomplete on certain keys for example
                 onBeforeMask: undefined, //executes before masking the initial value to allow preprocessing of the initial value.  args => initialValue, opts => return processedValue
@@ -1648,7 +1651,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2014 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.0.33
+* Version: 3.0.34
 */
 
 (function ($) {
@@ -2013,7 +2016,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.33
+Version: 3.0.34
 
 Optional extensions on the jquery.inputmask base
 */
@@ -2134,7 +2137,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.33
+Version: 3.0.34
 
 Optional extensions on the jquery.inputmask base
 */
@@ -2597,7 +2600,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.33
+Version: 3.0.34
 
 Optional extensions on the jquery.inputmask base
 */
@@ -2641,7 +2644,6 @@ Optional extensions on the jquery.inputmask base
             allowPlus: true,
             allowMinus: true,
             integerDigits: "+", //number of integerDigits
-            defaultValue: "",
             prefix: "",
             suffix: "",
             skipRadixDance: false, //disable radixpoint caret positioning
@@ -2703,30 +2705,43 @@ Optional extensions on the jquery.inputmask base
             regex: {
                 integerPart: function (opts) { return new RegExp('[-\+]?\\d+'); }
             },
+            negationhandler: function (chrs, buffer, pos, strict, opts) {
+                if (!strict && opts.allowMinus && chrs === "-") {
+                    var matchRslt = buffer.join('').match(opts.regex.integerPart(opts));
+
+                    if (matchRslt.length > 0) {
+                        if (buffer[matchRslt.index] == "+") {
+                            buffer.splice(matchRslt.index, 1);
+                            return { "pos": matchRslt.index, "c": "-", "refreshFromBuffer": true, "caret": pos };
+                        } else if (buffer[matchRslt.index] == "-") {
+                            buffer.splice(matchRslt.index, 1);
+                            return { "refreshFromBuffer": true, "caret": pos - 1 };
+                        } else {
+                            return { "pos": matchRslt.index, "c": "-", "caret": pos + 1 };
+                        }
+                    }
+                }
+                return false;
+            },
             definitions: {
                 '~': {
                     validator: function (chrs, buffer, pos, strict, opts) {
-                        if (!strict && opts.allowMinus && chrs === "-") {
-                            var matchRslt = buffer.join('').match(opts.regex.integerPart(opts));
-
-                            if (matchRslt.length > 0) {
-                                if (buffer[matchRslt.index] == "+") {
-                                    buffer.splice(matchRslt.index, 1);
-                                    return { "pos": matchRslt.index, "c": "-", "refreshFromBuffer": true, "caret": pos };
-                                } else if (buffer[matchRslt.index] == "-") {
-                                    buffer.splice(matchRslt.index, 1);
-                                    return { "refreshFromBuffer": true, "caret": pos - 1 };
-                                } else {
-                                    return { "pos": matchRslt.index, "c": "-", "caret": pos + 1 };
-                                }
+                        var isValid = opts.negationhandler(chrs, buffer, pos, strict, opts);
+                        if (!isValid) {
+                            //handle 0 for integerpart
+                            //if (!strict && chrs === "0") {
+                            //    var matchRslt = buffer.join('').match(opts.regex.integerPart(opts));
+                            //    if (matchRslt && matchRslt[matchRslt.index].indexOf("0") == -1) {
+                            //        return false;
+                            //    }
+                            //}
+
+                            isValid = strict ? new RegExp("[0-9" + $.inputmask.escapeRegex.call(this, opts.groupSeparator) + "]").test(chrs) : new RegExp("[0-9]").test(chrs);
+
+                            if (isValid != false && !strict && chrs != opts.radixPoint && opts.autoGroup === true) {
+                                return opts.postFormat(buffer, pos, (chrs == "-" || chrs == "+") ? true : false, opts);
                             }
                         }
-                        var isValid = strict ? new RegExp("[0-9" + $.inputmask.escapeRegex.call(this, opts.groupSeparator) + "]").test(chrs) : new RegExp("[0-9]").test(chrs);
-
-                        if (isValid != false && !strict && chrs != opts.radixPoint && opts.autoGroup === true) {
-                            return opts.postFormat(buffer, pos, (chrs == "-" || chrs == "+") ? true : false, opts);
-                        }
-
                         return isValid;
                     },
                     cardinality: 1,
@@ -2762,7 +2777,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.33
+Version: 3.0.34
 
 Regex extensions on the jquery.inputmask base
 Allows for using regular expressions as a mask
@@ -2949,7 +2964,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.33
+Version: 3.0.34
 
 Phone extension.
 When using this extension make sure you specify the correct url to get the masks

ファイルの差分が大きいため隠しています
+ 80 - 79
dist/jquery.inputmask.bundle.min.js


ファイルの差分が大きいため隠しています
+ 1 - 1
dist/min/jquery.inputmask-multi.js


ファイルの差分が大きいため隠しています
+ 37 - 36
dist/min/jquery.inputmask.js


ファイルの差分が大きいため隠しています
+ 6 - 6
dist/min/jquery.inputmask.numeric.extensions.js


+ 1 - 1
jquery.inputmask.jquery.json

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

+ 6 - 3
js/jquery.inputmask.js

@@ -586,12 +586,14 @@
                                     return false;//breakout if refreshFromBuffer && nothing to insert
                                 }
                                 validatedPos = rslt.pos != undefined ? rslt.pos : position;
-                                tst = getTests(validatedPos)[0]; //possible mismatch TODO
+                                if (validatedPos != position)
+                                    tst = getTests(validatedPos)[0]; //possible mismatch TODO
 
                             } else if (rslt !== true && rslt["pos"] != position) { //their is a position offset
                                 validatedPos = rslt["pos"];
                                 refreshFromBuffer(position, validatedPos);
-                                tst = getTests(validatedPos)[0]; //possible mismatch TODO
+                                if (validatedPos != position)
+                                    tst = getTests(validatedPos)[0]; //possible mismatch TODO
                             }
                             if (ndx > 0) {
                                 resetMaskSet(true);
@@ -606,6 +608,7 @@
                 }
 
                 var maskPos = pos;
+                if (maskPos >= getMaskLength()) return false;
                 var result = _isValid(maskPos, c, strict, fromSetValid);
                 if (!strict && result === false) {
                     var currentPosValid = getMaskSet()["validPositions"][maskPos];
@@ -1479,7 +1482,7 @@
                 insertMode: true, //insert the input or overwrite the input
                 clearIncomplete: false, //clear the incomplete input on blur
                 aliases: {}, //aliases definitions => see jquery.inputmask.extensions.js
-				alias: null,
+                alias: null,
                 onKeyUp: $.noop, //override to implement autocomplete on certain keys for example
                 onKeyDown: $.noop, //override to implement autocomplete on certain keys for example
                 onBeforeMask: undefined, //executes before masking the initial value to allow preprocessing of the initial value.  args => initialValue, opts => return processedValue

+ 31 - 19
js/jquery.inputmask.numeric.extensions.js

@@ -47,7 +47,6 @@ Optional extensions on the jquery.inputmask base
             allowPlus: true,
             allowMinus: true,
             integerDigits: "+", //number of integerDigits
-            defaultValue: "",
             prefix: "",
             suffix: "",
             skipRadixDance: false, //disable radixpoint caret positioning
@@ -109,30 +108,43 @@ Optional extensions on the jquery.inputmask base
             regex: {
                 integerPart: function (opts) { return new RegExp('[-\+]?\\d+'); }
             },
+            negationhandler: function (chrs, buffer, pos, strict, opts) {
+                if (!strict && opts.allowMinus && chrs === "-") {
+                    var matchRslt = buffer.join('').match(opts.regex.integerPart(opts));
+
+                    if (matchRslt.length > 0) {
+                        if (buffer[matchRslt.index] == "+") {
+                            buffer.splice(matchRslt.index, 1);
+                            return { "pos": matchRslt.index, "c": "-", "refreshFromBuffer": true, "caret": pos };
+                        } else if (buffer[matchRslt.index] == "-") {
+                            buffer.splice(matchRslt.index, 1);
+                            return { "refreshFromBuffer": true, "caret": pos - 1 };
+                        } else {
+                            return { "pos": matchRslt.index, "c": "-", "caret": pos + 1 };
+                        }
+                    }
+                }
+                return false;
+            },
             definitions: {
                 '~': {
                     validator: function (chrs, buffer, pos, strict, opts) {
-                        if (!strict && opts.allowMinus && chrs === "-") {
-                            var matchRslt = buffer.join('').match(opts.regex.integerPart(opts));
+                        var isValid = opts.negationhandler(chrs, buffer, pos, strict, opts);
+                        if (!isValid) {
+                            //handle 0 for integerpart
+                            //if (!strict && chrs === "0") {
+                            //    var matchRslt = buffer.join('').match(opts.regex.integerPart(opts));
+                            //    if (matchRslt && matchRslt[matchRslt.index].indexOf("0") == -1) {
+                            //        return false;
+                            //    }
+                            //}
 
-                            if (matchRslt.length > 0) {
-                                if (buffer[matchRslt.index] == "+") {
-                                    buffer.splice(matchRslt.index, 1);
-                                    return { "pos": matchRslt.index, "c": "-", "refreshFromBuffer": true, "caret": pos };
-                                } else if (buffer[matchRslt.index] == "-") {
-                                    buffer.splice(matchRslt.index, 1);
-                                    return { "refreshFromBuffer": true, "caret": pos - 1 };
-                                } else {
-                                    return { "pos": matchRslt.index, "c": "-", "caret": pos + 1 };
-                                }
-                            }
-                        }
-                        var isValid = strict ? new RegExp("[0-9" + $.inputmask.escapeRegex.call(this, opts.groupSeparator) + "]").test(chrs) : new RegExp("[0-9]").test(chrs);
+                            isValid = strict ? new RegExp("[0-9" + $.inputmask.escapeRegex.call(this, opts.groupSeparator) + "]").test(chrs) : new RegExp("[0-9]").test(chrs);
 
-                        if (isValid != false && !strict && chrs != opts.radixPoint && opts.autoGroup === true) {
-                            return opts.postFormat(buffer, pos, (chrs == "-" || chrs == "+") ? true : false, opts);
+                            if (isValid != false && !strict && chrs != opts.radixPoint && opts.autoGroup === true) {
+                                return opts.postFormat(buffer, pos, (chrs == "-" || chrs == "+") ? true : false, opts);
+                            }
                         }
-
                         return isValid;
                     },
                     cardinality: 1,