浏览代码

get the pressed key onKeyValidation fix #1114

Robin Herbots 10 年之前
父节点
当前提交
3125e434bf
共有 3 个文件被更改,包括 9 次插入8 次删除
  1. 1 0
      CHANGELOG.md
  2. 4 4
      README.md
  3. 4 4
      js/inputmask.js

+ 1 - 0
CHANGELOG.md

@@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file.
 - fix for bower package
 
 ### Fixed
+- get the pressed key onKeyValidation #1114
 - write a global function for onKeyValidation #1111
 - NumericInput Causes err #856
 - Certain phones not inputable #758

+ 4 - 4
README.md

@@ -410,7 +410,7 @@ All callbacks are implemented as options.  This means that you can set general i
 
 ```javascript
 Inputmask.extendDefaults({
-    onKeyValidation: function(result){
+    onKeyValidation: function(key, result){
                         if (!result){
                             alert('Your input is not valid')
                           }
@@ -833,13 +833,13 @@ $(document).ready(function(){
 ```
 
 ### onKeyValidation
-Callback function is executed on every keyvalidation with the result as parameter.
+Callback function is executed on every keyvalidation with the key & result as parameter.
 
 ```javascript
 $(document).ready(function(){
     $("#ssn").inputmask("999-99-9999",
-            { onKeyValidation: function (result) {
-                                console.log(result);
+            { onKeyValidation: function (key, result) {
+                                console.log(key + " - " + result);
                                 } });
 });
 ```

+ 4 - 4
js/inputmask.js

@@ -76,7 +76,7 @@
 				onUnMask: null, //executes after unmasking to allow postprocessing of the unmaskedvalue.	args => maskedValue, unmaskedValue, opts
 				showMaskOnFocus: true, //show the mask-placeholder when the input has focus
 				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: key, result, opts
 				skipOptionalPartCharacter: " ", //a character which can be used to skip an optional part of a mask
 				showTooltip: false, //show the activemask as tooltip
 				tooltip: undefined, //tooltip to show
@@ -2200,7 +2200,7 @@
 						if (writeOut !== false) {
 							var self = this;
 							setTimeout(function() {
-								opts.onKeyValidation.call(self, valResult, opts);
+								opts.onKeyValidation.call(self, k, valResult, opts);
 							}, 0);
 							if (getMaskSet().writeOutBuffer && valResult !== false) {
 								var buffer = getBuffer();
@@ -2545,7 +2545,7 @@
 				patchValueProperty(el);
 				if ((el.tagName === "INPUT" && isInputTypeSupported(el.getAttribute("type"))) || el.isContentEditable) {
 					//bind events
-					$(el.form).on("submit", function() { //trigger change on submit if any
+					$(el.form).on("submit.inputmask", function() { //trigger change on submit if any
 						if (undoValue !== getBuffer().join("")) {
 							$el.trigger("change");
 						}
@@ -2558,7 +2558,7 @@
 								writeBuffer(el, getBuffer());
 							}, 0);
 						}
-					}).on("reset", function() {
+					}).on("reset.inputmask", function() {
 						setTimeout(function() {
 							$el.trigger("setvalue.inputmask");
 						}, 0);