Browse Source

enhance radixhandling for non-greedy masks

Robin Herbots 13 years ago
parent
commit
5a8ba26eab
1 changed files with 10 additions and 5 deletions
  1. 10 5
      js/jquery.inputmask.js

+ 10 - 5
js/jquery.inputmask.js

@@ -3,7 +3,7 @@ Input Mask plugin for jquery
 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: 1.0.6
+Version: 1.0.7
  
 This plugin is based on the masked input plugin written by Josh Bush (digitalbush.com)
 */
@@ -413,7 +413,12 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
                     }
                 }
                 //Truncate buffer when using non-greedy masks
-                buffer = TruncateInput(buffer.join(''), isRTL).split('');
+                if (opts.greedy == false) {
+                    var newBuffer = TruncateInput(buffer.join(''), isRTL).split('');
+                    while (buffer.length != newBuffer.length) {  //map changes into the original buffer
+                        isRTL ? buffer.shift() : buffer.pop();
+                    }
+                }
 
                 if (clearInvalid) {
                     writeBuffer(input, buffer);
@@ -787,13 +792,13 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
                                 beginPos = firstMaskPos;
                             }
                             if (beginPos >= firstMaskPos) {
-                                if (opts.numericInput && k == opts.keyCode.DELETE && buffer[beginPos] == opts.radixPoint[opts.radixPoint.length - 1]) {
+                                if (opts.numericInput && opts.greedy && k == opts.keyCode.DELETE && buffer[beginPos] == opts.radixPoint[opts.radixPoint.length - 1]) {
                                     beginPos = seekNext(buffer, beginPos);
                                     isRTL = false;
                                 }
                                 if (isRTL) {
                                     beginPos = shiftR(firstMaskPos, beginPos, getPlaceHolder(beginPos), true);
-                                    beginPos = (opts.numericInput && k == opts.keyCode.BACKSPACE && buffer[beginPos + 1] == opts.radixPoint[opts.radixPoint.length - 1]) ? beginPos + 1 : seekNext(buffer, beginPos);
+                                    beginPos = (opts.numericInput && opts.greedy && k == opts.keyCode.BACKSPACE && buffer[beginPos + 1] == opts.radixPoint[opts.radixPoint.length - 1]) ? beginPos + 1 : seekNext(buffer, beginPos);
                                 } else beginPos = shiftL(beginPos, maskL);
                                 writeBuffer(input, buffer, beginPos);
                             }
@@ -910,4 +915,4 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
             }
         };
     }
-})(jQuery); 
+})(jQuery);