ソースを参照

Change return of isValid fn to allow changing the typed input char

Robin Herbots 13 年 前
コミット
5fb2641311
1 ファイル変更15 行追加5 行削除
  1. 15 5
      js/jquery.inputmask.js

+ 15 - 5
js/jquery.inputmask.js

@@ -3,7 +3,7 @@ Input Mask plugin for jquery
 http://github.com/RobinHerbots/jquery.inputmask
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2012 Robin Herbots
 Copyright (c) 2010 - 2012 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 1.0.8
+Version: 1.0.9
  
  
 This plugin is based on the masked input plugin written by Josh Bush (digitalbush.com)
 This plugin is based on the masked input plugin written by Josh Bush (digitalbush.com)
 */
 */
@@ -256,6 +256,7 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
                 }
                 }
 
 
                 if (c) { chrs += c; }
                 if (c) { chrs += c; }
+                //return is false or a json object => { pos: ??, c: ??}
                 return tests[testPos].fn != null ? tests[testPos].fn.test(chrs, buffer, pos, strict, opts) : false;
                 return tests[testPos].fn != null ? tests[testPos].fn.test(chrs, buffer, pos, strict, opts) : false;
             }
             }
 
 
@@ -391,7 +392,10 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
                         if (isMask(pos)) {
                         if (isMask(pos)) {
                             var c = inputValue[i];
                             var c = inputValue[i];
                             if ((np = isValid(pos, c, buffer, !clearInvalid)) !== false) {
                             if ((np = isValid(pos, c, buffer, !clearInvalid)) !== false) {
-                                if (np !== true) pos = np; //set new position from isValid
+                                if (np !== true) {
+                                    pos = np.pos || pos; //set new position from isValid
+                                    c = np.c || c; //set new char from isValid
+                                }
                                 setBufferElement(buffer, pos, c);
                                 setBufferElement(buffer, pos, c);
                                 lastMatch = checkPosition = pos;
                                 lastMatch = checkPosition = pos;
                             } else {
                             } else {
@@ -871,7 +875,10 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
                             if (isRTL) {
                             if (isRTL) {
                                 var p = opts.numericInput ? pos.end : seekPrevious(buffer, pos.end), np;
                                 var p = opts.numericInput ? pos.end : seekPrevious(buffer, pos.end), np;
                                 if ((np = isValid(p == maskL || getBufferElement(buffer, p) == opts.radixPoint[opts.radixPoint.length - 1] ? seekPrevious(buffer, p) : p, c, buffer, false)) !== false) {
                                 if ((np = isValid(p == maskL || getBufferElement(buffer, p) == opts.radixPoint[opts.radixPoint.length - 1] ? seekPrevious(buffer, p) : p, c, buffer, false)) !== false) {
-                                    if (np !== true) p = np; //set new position from isValid
+                                    if (np !== true) {
+                                        p = np.pos || pos; //set new position from isValid
+                                        c = np.c || c; //set new char from isValid
+                                    }
                                     if (isValid(firstMaskPos, buffer[firstMaskPos], buffer, true) == false || (opts.greedy === false && buffer.length < maskL)) {
                                     if (isValid(firstMaskPos, buffer[firstMaskPos], buffer, true) == false || (opts.greedy === false && buffer.length < maskL)) {
                                         if (buffer[firstMaskPos] != getPlaceHolder(firstMaskPos) && buffer.length < maskL) {
                                         if (buffer[firstMaskPos] != getPlaceHolder(firstMaskPos) && buffer.length < maskL) {
                                             var offset = prepareBuffer(buffer, -1, isRTL);
                                             var offset = prepareBuffer(buffer, -1, isRTL);
@@ -888,7 +895,10 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
                                 var p = seekNext(buffer, pos.begin - 1), np;
                                 var p = seekNext(buffer, pos.begin - 1), np;
                                 prepareBuffer(buffer, p, isRTL);
                                 prepareBuffer(buffer, p, isRTL);
                                 if ((np = isValid(p, c, buffer, false)) !== false) {
                                 if ((np = isValid(p, c, buffer, false)) !== false) {
-                                    if (np !== true) p = np; //set new position from isValid
+                                    if (np !== true) {
+                                        p = np.pos || p; //set new position from isValid
+                                        c = np.c || c; //set new char from isValid
+                                    }
                                     if (opts.insertMode == true) {
                                     if (opts.insertMode == true) {
                                         var lastUnmaskedPosition = getMaskLength();
                                         var lastUnmaskedPosition = getMaskLength();
                                         while (getBufferElement(buffer, lastUnmaskedPosition) != getPlaceHolder(lastUnmaskedPosition) && lastUnmaskedPosition >= p) {
                                         while (getBufferElement(buffer, lastUnmaskedPosition) != getPlaceHolder(lastUnmaskedPosition) && lastUnmaskedPosition >= p) {
@@ -925,4 +935,4 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
             }
             }
         };
         };
     }
     }
-})(jQuery);  
+})(jQuery);