Browse Source

change postvalidation functionality

Robin Herbots 9 years ago
parent
commit
ef9d129a3c
4 changed files with 11 additions and 19 deletions
  1. 1 0
      CHANGELOG.md
  2. 1 1
      README.md
  3. 7 12
      js/inputmask.js
  4. 2 6
      js/inputmask.numeric.extensions.js

+ 1 - 0
CHANGELOG.md

@@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
 - VIN mask #1199
 - VIN mask #1199
 
 
 ### Updates
 ### Updates
+- change funtionality of postValidation => result may be true|false
 - improve getmetadata
 - improve getmetadata
 - patchValueProperty - enable native value property patch on IE10/IE11
 - patchValueProperty - enable native value property patch on IE10/IE11
 
 

+ 1 - 1
README.md

@@ -950,7 +950,7 @@ $(selector).inputmask("Regex", {
 Hook to alter the clear behavior in the stripValidPositions<br>Args => maskset, position, lastValidPosition, opts<br>Return => true|false
 Hook to alter the clear behavior in the stripValidPositions<br>Args => maskset, position, lastValidPosition, opts<br>Return => true|false
 
 
 ### postValidation
 ### postValidation
-Hook to postValidate the result from isValid.  Usefull for validating the entry as a whole.  Args => buffer, currentResult, opts<br>Return => true|false/refresh command
+Hook to postValidate the result from isValid.  Usefull for validating the entry as a whole.  Args => buffer, currentResult, opts<br>Return => true|false
 
 
 ### staticDefinitionSymbol
 ### staticDefinitionSymbol
 The staticDefinitionSymbol option is used to indicate that the static entries in the mask can match a certain definition.  Especially usefull with alternators so that static element in the mask can match another alternation.  
 The staticDefinitionSymbol option is used to indicate that the static entries in the mask can match a certain definition.  Especially usefull with alternators so that static element in the mask can match another alternation.  

+ 7 - 12
js/inputmask.js

@@ -115,7 +115,7 @@
 				ignorables: [8, 9, 13, 19, 27, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46, 93, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123],
 				ignorables: [8, 9, 13, 19, 27, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46, 93, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123],
 				isComplete: null, //override for isComplete - args => buffer, opts - return true || false
 				isComplete: null, //override for isComplete - args => buffer, opts - return true || false
 				canClearPosition: $.noop, //hook to alter the clear behavior in the stripValidPositions args => maskset, position, lastValidPosition, opts => return true|false
 				canClearPosition: $.noop, //hook to alter the clear behavior in the stripValidPositions args => maskset, position, lastValidPosition, opts => return true|false
-				postValidation: null, //hook to postValidate the result from isValid.	Usefull for validating the entry as a whole.	args => buffer, currentResult, opts => return true/false/refresh command
+				postValidation: null, //hook to postValidate the result from isValid.	Usefull for validating the entry as a whole.	args => buffer, currentResult, opts => return true/false
 				staticDefinitionSymbol: undefined, //specify a definitionSymbol for static content, used to make matches for alternators
 				staticDefinitionSymbol: undefined, //specify a definitionSymbol for static content, used to make matches for alternators
 				jitMasking: false //just in time masking ~ only mask while typing, can n (number), true or false
 				jitMasking: false //just in time masking ~ only mask while typing, can n (number), true or false
 			},
 			},
@@ -1570,17 +1570,12 @@
 					};
 					};
 				}
 				}
 				if ($.isFunction(opts.postValidation) && result !== false && !strict && fromSetValid !== true) {
 				if ($.isFunction(opts.postValidation) && result !== false && !strict && fromSetValid !== true) {
-					var postValidResult = opts.postValidation(getBuffer(true), result, opts);
-					if (!postValidResult) {
-						resetMaskSet(true);
-						getMaskSet().validPositions = $.extend(true, {}, positionsClone); //revert validation changes
-						result = false;
-					} else if (postValidResult.refreshFromBuffer) {
-						var refresh = postValidResult.refreshFromBuffer;
-						refreshFromBuffer(refresh === true ? refresh : refresh.start, refresh.end, postValidResult.buffer);
-						resetMaskSet(true);
-						result = postValidResult;
-					}
+					result = opts.postValidation(getBuffer(true), result, opts) ? result : false;
+				}
+
+				if (result === false) {
+					resetMaskSet(true);
+					getMaskSet().validPositions = $.extend(true, {}, positionsClone); //revert validation changes
 				}
 				}
 
 
 				return result;
 				return result;

+ 2 - 6
js/inputmask.numeric.extensions.js

@@ -442,12 +442,7 @@ Optional extensions on the jquery.inputmask base
 
 
 					if (isFinite(processValue)) {
 					if (isFinite(processValue)) {
 						if (opts.max !== null && isFinite(opts.max)) {
 						if (opts.max !== null && isFinite(opts.max)) {
-							processValue = parseFloat(processValue) > parseFloat(opts.max) ? opts.max : processValue;
-							isValid = opts.postFormat((opts.prefix + processValue).split(""), 0, true, opts);
-						}
-						if (opts.min !== null && isFinite(opts.min)) {
-							processValue = parseFloat(processValue) < parseFloat(opts.min) ? opts.min : processValue;
-							isValid = opts.postFormat((opts.prefix + processValue).split(""), 0, true, opts);
+							isValid = parseFloat(processValue) <= parseFloat(opts.max);
 						}
 						}
 					}
 					}
 
 
@@ -626,6 +621,7 @@ Optional extensions on the jquery.inputmask base
 						positionInput === opts.negationSymbol.front ||
 						positionInput === opts.negationSymbol.front ||
 						positionInput === opts.negationSymbol.back;
 						positionInput === opts.negationSymbol.back;
 
 
+					return canClear;
 					if (canClear && isFinite(positionInput)) {
 					if (canClear && isFinite(positionInput)) {
 						var matchRslt,
 						var matchRslt,
 							radixPos = $.inArray(opts.radixPoint, maskset.buffer);
 							radixPos = $.inArray(opts.radixPoint, maskset.buffer);