浏览代码

Distinguish empty value and '$ 0.00' value for currency alias fix #1053

Robin Herbots 9 年之前
父节点
当前提交
9bdf6316a7

+ 2 - 0
CHANGELOG.md

@@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.
 ## UNRELEASED
 
 ### Added
+- nullable option => switch to return the placeholder or null when nothing is entered
 - VIN mask #1199
 
 ### Updates
@@ -14,6 +15,7 @@ All notable changes to this project will be documented in this file.
 - patchValueProperty - enable native value property patch on IE10/IE11
 
 ### Fixed
+- Distinguish empty value and '$ 0.00' value for currency alias #1053
 - 'alias': 'numeric', zero value #1221
 - Clicking on a highlighted masked field does not set the caret to the first valid position (Chrome) #1218
 - Caret Positioned After Last Decimal Digit Disallows Sign Input When digits Option Set #1139

+ 4 - 0
README.md

@@ -974,6 +974,10 @@ Inputmask("(99 99 999999)|(i{+})", {
 }).mask(selector);
 ```
 
+### nullable
+Return nothing when the user hasn't entered anything.
+Default: true
+
 ## General
 ### set a value and apply mask
 this can be done with the traditional jquery.val function (all browsers) or JavaScript value property for browsers which implement lookupGetter or getOwnPropertyDescriptor

+ 20 - 20
README_numeric.md

@@ -1,46 +1,46 @@
 # numeric extensions
 ## Aliases
 
-- numeric  
-- currency  
-- decimal  
-- integer  
-- percentage  
+- numeric
+- currency
+- decimal
+- integer
+- percentage
 
 ## Options
 ### digits
-Number of fractionalDigits  
+Number of fractionalDigits
 Default: "*"
 
 ### digitsOptional
-Specify wheter the digits are optional.  
+Specify wheter the digits are optional.
 Default: true
 
 ### groupSize
-Define the grouping of the integer part.  
+Define the grouping of the integer part.
 Default: 3
 
 ### autoGroup
-Enable grouping of the integer part.  
+Enable grouping of the integer part.
 Default: false
 
 ### allowPlus
-Allow to enter +.  
+Allow to enter +.
 Default: true
 
 ### allowMinus
-Allow to enter -.  
+Allow to enter -.
 Default: true
 
 ### negationSymbol
-Define your negationSymbol.  
-Default: {  
-  front: "-", //"("  
-  back: "" //")"  
+Define your negationSymbol.
+Default: {
+  front: "-", //"("
+  back: "" //")"
 }
 
 ### integerDigits
-Number of integerDigits  
+Number of integerDigits
 Default: "+"
 
 ### integerOptional
@@ -48,15 +48,15 @@ Specify wheter the integerdigits are optional.
 Default: true
 
 ### prefix
-Define a prefix.  
+Define a prefix.
 Default: ""
 
 ### suffix
-Define a suffix.  
+Define a suffix.
 Default: ""
 
 ### decimalProtect
-Do not allow assumption of decimals input without entering the radixpoint.  
+Do not allow assumption of decimals input without entering the radixpoint.
 Default: true
 
 ### min
@@ -72,5 +72,5 @@ Define the step the ctrl-up & ctrl-down must take.
 Default: 1
 
 ### unmaskAsNumber
-Make unmasking returning a number instead of a string.  
+Make unmasking returning a number instead of a string.
 Default: false

+ 1 - 1
bower.json

@@ -1,6 +1,6 @@
 {
   "name": "jquery.inputmask",
-  "version": "3.2.8-31",
+  "version": "3.2.8-32",
   "main": [
     "./dist/inputmask/inputmask.js"
   ],

+ 1 - 1
component.json

@@ -2,7 +2,7 @@
   "name": "jquery_inputmask",
   "repository": "robinherbots/jquery.inputmask",
   "description": "jquery.inputmask is a jquery plugin which create an input mask.",
-  "version": "3.2.8-31",
+  "version": "3.2.8-32",
   "keywords": ["jquery", "plugins", "input", "form", "inputmask", "mask"],
   "main": "./dist/jquery.inputmask.bundle.js",
   "scripts": [

+ 1 - 1
composer.json

@@ -1,7 +1,7 @@
 {
   "name": "robinherbots/jquery.inputmask",
   "description": "jquery.inputmask is a jquery plugin which create an input mask.",
-  "version": "3.2.8-31",
+  "version": "3.2.8-32",
   "type": "library",
   "keywords": ["jquery", "plugins", "input", "form", "inputmask", "mask"],
   "homepage": "http://robinherbots.github.io/jquery.inputmask",

+ 1 - 1
dist/inputmask/inputmask.date.extensions.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2016 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.2.8-31
+* Version: 3.2.8-32
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "inputmask.dependencyLib", "inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("./inputmask.dependencyLib.jquery"), require("./inputmask")) : factory(window.dependencyLib || jQuery, window.Inputmask);

+ 1 - 1
dist/inputmask/inputmask.dependencyLib.jquery.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2016 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.2.8-31
+* Version: 3.2.8-32
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery")) : factory(jQuery);

+ 1 - 1
dist/inputmask/inputmask.extensions.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2016 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.2.8-31
+* Version: 3.2.8-32
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "inputmask.dependencyLib", "inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("./inputmask.dependencyLib.jquery"), require("./inputmask")) : factory(window.dependencyLib || jQuery, window.Inputmask);

+ 5 - 4
dist/inputmask/inputmask.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2016 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.2.8-31
+* Version: 3.2.8-32
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "inputmask.dependencyLib" ], factory) : "object" == typeof exports ? module.exports = factory(require("./inputmask.dependencyLib.jquery")) : factory(window.dependencyLib || jQuery);
@@ -829,7 +829,7 @@
                             if (elem.inputmask) {
                                 if (elem.inputmask.opts.autoUnmask) return elem.inputmask.unmaskedvalue();
                                 var result = valhookGet(elem);
-                                return -1 !== getLastValidPosition() ? result : "";
+                                return -1 !== getLastValidPosition() || opts.nullable !== !0 ? result : "";
                             }
                             return valhookGet(elem);
                         },
@@ -843,7 +843,7 @@
                 }
             }
             function getter() {
-                return this.inputmask ? this.inputmask.opts.autoUnmask ? this.inputmask.unmaskedvalue() : -1 !== getLastValidPosition() ? document.activeElement === this && opts.clearMaskOnLostFocus ? (isRTL ? clearOptionalTail(getBuffer().slice()).reverse() : clearOptionalTail(getBuffer().slice())).join("") : valueGet.call(this) : "" : valueGet.call(this);
+                return this.inputmask ? this.inputmask.opts.autoUnmask ? this.inputmask.unmaskedvalue() : -1 !== getLastValidPosition() || opts.nullable !== !0 ? document.activeElement === this && opts.clearMaskOnLostFocus ? (isRTL ? clearOptionalTail(getBuffer().slice()).reverse() : clearOptionalTail(getBuffer().slice())).join("") : valueGet.call(this) : "" : valueGet.call(this);
             }
             function setter(value) {
                 valueSet.call(this, value), this.inputmask && $(this).trigger("setvalue");
@@ -1320,7 +1320,8 @@
             canClearPosition: $.noop,
             postValidation: null,
             staticDefinitionSymbol: void 0,
-            jitMasking: !1
+            jitMasking: !1,
+            nullable: !0
         },
         masksCache: {},
         mask: function(elems) {

+ 1 - 1
dist/inputmask/inputmask.numeric.extensions.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2016 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.2.8-31
+* Version: 3.2.8-32
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "inputmask.dependencyLib", "inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("./inputmask.dependencyLib.jquery"), require("./inputmask")) : factory(window.dependencyLib || jQuery, window.Inputmask);

+ 1 - 1
dist/inputmask/inputmask.phone.extensions.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2016 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.2.8-31
+* Version: 3.2.8-32
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery"), require("./inputmask")) : factory(window.dependencyLib || jQuery, window.Inputmask);

+ 1 - 1
dist/inputmask/inputmask.regex.extensions.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2016 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.2.8-31
+* Version: 3.2.8-32
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "inputmask.dependencyLib", "inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("./inputmask.dependencyLib.jquery"), require("./inputmask")) : factory(window.dependencyLib || jQuery, window.Inputmask);

+ 1 - 1
dist/inputmask/jquery.inputmask.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2016 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.2.8-31
+* Version: 3.2.8-32
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery"), require("./inputmask")) : factory(jQuery, window.Inputmask);

+ 5 - 4
dist/jquery.inputmask.bundle.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2016 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.2.8-31
+* Version: 3.2.8-32
 */
 !function($) {
     function Inputmask(alias, options) {
@@ -827,7 +827,7 @@
                             if (elem.inputmask) {
                                 if (elem.inputmask.opts.autoUnmask) return elem.inputmask.unmaskedvalue();
                                 var result = valhookGet(elem);
-                                return -1 !== getLastValidPosition() ? result : "";
+                                return -1 !== getLastValidPosition() || opts.nullable !== !0 ? result : "";
                             }
                             return valhookGet(elem);
                         },
@@ -841,7 +841,7 @@
                 }
             }
             function getter() {
-                return this.inputmask ? this.inputmask.opts.autoUnmask ? this.inputmask.unmaskedvalue() : -1 !== getLastValidPosition() ? document.activeElement === this && opts.clearMaskOnLostFocus ? (isRTL ? clearOptionalTail(getBuffer().slice()).reverse() : clearOptionalTail(getBuffer().slice())).join("") : valueGet.call(this) : "" : valueGet.call(this);
+                return this.inputmask ? this.inputmask.opts.autoUnmask ? this.inputmask.unmaskedvalue() : -1 !== getLastValidPosition() || opts.nullable !== !0 ? document.activeElement === this && opts.clearMaskOnLostFocus ? (isRTL ? clearOptionalTail(getBuffer().slice()).reverse() : clearOptionalTail(getBuffer().slice())).join("") : valueGet.call(this) : "" : valueGet.call(this);
             }
             function setter(value) {
                 valueSet.call(this, value), this.inputmask && $(this).trigger("setvalue");
@@ -1318,7 +1318,8 @@
             canClearPosition: $.noop,
             postValidation: null,
             staticDefinitionSymbol: void 0,
-            jitMasking: !1
+            jitMasking: !1,
+            nullable: !0
         },
         masksCache: {},
         mask: function(elems) {

文件差异内容过多而无法显示
+ 1 - 1
dist/min/inputmask/inputmask.date.extensions.min.js


+ 1 - 1
dist/min/inputmask/inputmask.dependencyLib.jquery.min.js

@@ -3,6 +3,6 @@
 * https://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2016 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.2.8-31
+* Version: 3.2.8-32
 */
 !function(a){"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof exports?module.exports=a(require("jquery")):a(jQuery)}(function(a){return window.dependencyLib=a,a});

文件差异内容过多而无法显示
+ 1 - 1
dist/min/inputmask/inputmask.extensions.min.js


文件差异内容过多而无法显示
+ 3 - 3
dist/min/inputmask/inputmask.min.js


文件差异内容过多而无法显示
+ 1 - 1
dist/min/inputmask/inputmask.numeric.extensions.min.js


文件差异内容过多而无法显示
+ 1 - 1
dist/min/inputmask/inputmask.phone.extensions.min.js


文件差异内容过多而无法显示
+ 1 - 1
dist/min/inputmask/inputmask.regex.extensions.min.js


文件差异内容过多而无法显示
+ 1 - 1
dist/min/inputmask/jquery.inputmask.min.js


文件差异内容过多而无法显示
+ 3 - 3
dist/min/jquery.inputmask.bundle.min.js


+ 4 - 3
js/inputmask.js

@@ -118,7 +118,8 @@
 			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
 			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
+			nullable: true //return nothing instead of the buffertemplate when nothing is returned.
 		},
 		masksCache: {},
 		mask: function (elems) {
@@ -2020,7 +2021,7 @@
 									return elem.inputmask.unmaskedvalue();
 								} else {
 									var result = valhookGet(elem);
-									return getLastValidPosition() !== -1 ? result : "";
+									return getLastValidPosition() !== -1 || opts.nullable !== true ? result : "";
 								}
 							} else return valhookGet(elem);
 						},
@@ -2042,7 +2043,7 @@
 				if (this.inputmask) {
 					return this.inputmask.opts.autoUnmask ?
 						this.inputmask.unmaskedvalue() :
-						(getLastValidPosition() !== -1 ?
+						(getLastValidPosition() !== -1 || opts.nullable !== true ?
 							(document.activeElement === this && opts.clearMaskOnLostFocus ?
 								(isRTL ? clearOptionalTail(getBuffer().slice()).reverse() : clearOptionalTail(getBuffer().slice())).join("") :
 								valueGet.call(this)) :

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "jquery.inputmask",
-  "version": "3.2.8-31",
+  "version": "3.2.8-32",
   "description": "jquery.inputmask is a jquery plugin which create an input mask.",
   "main": "./dist/inputmask/jquery.inputmask.js",
   "files": [