ソースを参照

added onUnMask postprocessing function #351

Robin Herbots 12 年 前
コミット
769dc73cc2
2 ファイル変更15 行追加1 行削除
  1. 12 0
      README.md
  2. 3 1
      js/jquery.inputmask.js

+ 12 - 0
README.md

@@ -132,6 +132,18 @@ $(document).ready(function(){
 });
 });
 ```
 ```
 
 
+### onUnMask
+Executes after unmasking to allow post-processing of the unmaskedvalue.  The arguments to the function are maskedValue, unmaskedValue.
+
+```javascript
+$(document).ready(function(){
+   $("#number").inputmask("decimal", { onUnMask: function(maskedValue, unmaskedValue) {
+		//do something with the value
+		return unmaskedValue;
+   }});
+});
+```
+
 ### set a value and apply mask
 ### set a value and apply mask
 
 
 this can be done with the traditionnal jquery.val function (all browsers) or javascript value property for browsers which implement lookupGetter or getOwnPropertyDescriptor
 this can be done with the traditionnal jquery.val function (all browsers) or javascript value property for browsers which implement lookupGetter or getOwnPropertyDescriptor

+ 3 - 1
js/jquery.inputmask.js

@@ -29,6 +29,7 @@
                 aliases: {}, //aliases definitions => see jquery.inputmask.extensions.js
                 aliases: {}, //aliases definitions => see jquery.inputmask.extensions.js
                 onKeyUp: $.noop, //override to implement autocomplete on certain keys for example
                 onKeyUp: $.noop, //override to implement autocomplete on certain keys for example
                 onKeyDown: $.noop, //override to implement autocomplete on certain keys for example
                 onKeyDown: $.noop, //override to implement autocomplete on certain keys for example
+                onUnMask: undefined, //executes after unmasking to allow postprocessing of the unmaskedvalue.  args => maskedValue, unmaskedValue
                 showMaskOnFocus: true, //show the mask-placeholder when the input has focus
                 showMaskOnFocus: true, //show the mask-placeholder when the input has focus
                 showMaskOnHover: true, //show the mask-placeholder when hovering the empty input
                 showMaskOnHover: true, //show the mask-placeholder when hovering the empty input
                 onKeyValidation: $.noop, //executes on every key-press with the result of isValid. Params: result, opts
                 onKeyValidation: $.noop, //executes on every key-press with the result of isValid. Params: result, opts
@@ -866,7 +867,8 @@
                         var umValue = $.map(getActiveBuffer(), function (element, index) {
                         var umValue = $.map(getActiveBuffer(), function (element, index) {
                             return isMask(index) && isValid(index, element, true) ? element : null;
                             return isMask(index) && isValid(index, element, true) ? element : null;
                         });
                         });
-                        return (isRTL ? umValue.reverse() : umValue).join('');
+                        var unmaskedValue = (isRTL ? umValue.reverse() : umValue).join('');
+                        return opts.onUnMask != undefined ? opts.onUnMask.call(this, getActiveBuffer().join(''), unmaskedValue) : unmaskedValue;
                     } else {
                     } else {
                         return $input[0]._valueGet();
                         return $input[0]._valueGet();
                     }
                     }