Browse Source

Decimal mask radixPoint ignored or mishandled while setting js decimal #499

Robin Herbots 11 years ago
parent
commit
53fbeee1b6

+ 1 - 1
bower.json

@@ -1,6 +1,6 @@
 {
     "name": "jquery.inputmask",
-    "version": "3.0.39",
+    "version": "3.0.40",
     "main": "./dist/jquery.inputmask.bundle.js",
 	"keywords" : ["jQuery", "plugins", "input", "form", "inputmask", "mask"],
 	"description": "jquery.inputmask is a jquery plugin which create an input mask.",

+ 1 - 1
build.properties

@@ -7,7 +7,7 @@ distdir = dist
 
 build.major = 3
 build.minor = 0
-build.revision = 39
+build.revision = 40
 
 target = jquery.inputmask.bundle.js
 target.min = jquery.inputmask.bundle.min.js

BIN
dist/jQuery.InputMask.3.0.39.nupkg


BIN
dist/jQuery.InputMask.3.0.40.nupkg


+ 31 - 14
dist/jquery.inputmask.bundle.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2014 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.0.39
+* Version: 3.0.40
 */
 
 (function ($) {
@@ -883,9 +883,13 @@
                                 } else return valueGet(elem);
                             },
                             set: function (elem, value) {
-                                var $elem = $(elem);
-                                var result = valueSet(elem, value);
-                                if ($elem.data('_inputmask')) $elem.triggerHandler('setvalue.inputmask');
+                                var $elem = $(elem), inputData = $elem.data('_inputmask'), result;
+                                if (inputData) {
+                                    result = valueSet(elem, $.isFunction(inputData['opts'].onBeforeMask) ? inputData['opts'].onBeforeMask.call(el, value, inputData['opts']) : value);
+                                    $elem.triggerHandler('setvalue.inputmask');
+                                } else {
+                                    result = valueSet(elem, value);
+                                }
                                 return result;
                             },
                             inputmaskpatch: true
@@ -915,8 +919,13 @@
                                 } else return valueGet.call(this);
                             },
                             set: function (value) {
-                                valueSet.call(this, value);
-                                $(this).triggerHandler('setvalue.inputmask');
+                                var inputData = $(this).data('_inputmask');
+                                if (inputData) {
+                                    valueSet.call(this, $.isFunction(inputData['opts'].onBeforeMask) ? inputData['opts'].onBeforeMask.call(el, value, inputData['opts']) : value);
+                                    $(this).triggerHandler('setvalue.inputmask');
+                                } else {
+                                    valueSet.call(this, value);
+                                }
                             }
                         });
                     }
@@ -938,8 +947,13 @@
                             } else return valueGet.call(this);
                         });
                         npt.__defineSetter__("value", function (value) {
-                            valueSet.call(this, value);
-                            $(this).triggerHandler('setvalue.inputmask');
+                            var inputData = $(this).data('_inputmask');
+                            if (inputData) {
+                                valueSet.call(this, $.isFunction(inputData['opts'].onBeforeMask) ? inputData['opts'].onBeforeMask.call(el, value, inputData['opts']) : value);
+                                $(this).triggerHandler('setvalue.inputmask');
+                            } else {
+                                valueSet.call(this, value);
+                            }
                         });
                     }
                 } else {
@@ -1664,7 +1678,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2014 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.0.39
+* Version: 3.0.40
 */
 
 (function ($) {
@@ -2029,7 +2043,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.39
+Version: 3.0.40
 
 Optional extensions on the jquery.inputmask base
 */
@@ -2150,7 +2164,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.39
+Version: 3.0.40
 
 Optional extensions on the jquery.inputmask base
 */
@@ -2613,7 +2627,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.39
+Version: 3.0.40
 
 Optional extensions on the jquery.inputmask base
 */
@@ -2790,6 +2804,9 @@ Optional extensions on the jquery.inputmask base
                 processValue = processValue.replace(new RegExp(opts.groupSeparator, "g"), "");
                 processValue = processValue.replace(opts.radixPoint, ".");
                 return isFinite(processValue);
+            },
+            onBeforeMask: function (initialValue, opts) {
+                return isFinite(initialValue) ? initialValue.toString().replace(".", opts.radixPoint) : initialValue;
             }
         },
         'decimal': {
@@ -2806,7 +2823,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.39
+Version: 3.0.40
 
 Regex extensions on the jquery.inputmask base
 Allows for using regular expressions as a mask
@@ -2993,7 +3010,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2014 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 3.0.39
+Version: 3.0.40
 
 Phone extension.
 When using this extension make sure you specify the correct url to get the masks

File diff suppressed because it is too large
+ 55 - 54
dist/jquery.inputmask.bundle.min.js


File diff suppressed because it is too large
+ 1 - 1
dist/min/jquery.inputmask-multi.js


File diff suppressed because it is too large
+ 53 - 52
dist/min/jquery.inputmask.js


File diff suppressed because it is too large
+ 1 - 1
dist/min/jquery.inputmask.numeric.extensions.js


+ 1 - 1
jquery.inputmask.jquery.json

@@ -8,7 +8,7 @@
 		"inputmask",
 		"mask"
     ],
-    "version": "3.0.39",
+    "version": "3.0.40",
     "author": {
         "name": "Robin Herbots",
         "url": "http://github.com/RobinHerbots/jquery.inputmask"

+ 21 - 7
js/jquery.inputmask.js

@@ -883,9 +883,13 @@
                                 } else return valueGet(elem);
                             },
                             set: function (elem, value) {
-                                var $elem = $(elem);
-                                var result = valueSet(elem, value);
-                                if ($elem.data('_inputmask')) $elem.triggerHandler('setvalue.inputmask');
+                                var $elem = $(elem), inputData = $elem.data('_inputmask'), result;
+                                if (inputData) {
+                                    result = valueSet(elem, $.isFunction(inputData['opts'].onBeforeMask) ? inputData['opts'].onBeforeMask.call(el, value, inputData['opts']) : value);
+                                    $elem.triggerHandler('setvalue.inputmask');
+                                } else {
+                                    result = valueSet(elem, value);
+                                }
                                 return result;
                             },
                             inputmaskpatch: true
@@ -915,8 +919,13 @@
                                 } else return valueGet.call(this);
                             },
                             set: function (value) {
-                                valueSet.call(this, value);
-                                $(this).triggerHandler('setvalue.inputmask');
+                                var inputData = $(this).data('_inputmask');
+                                if (inputData) {
+                                    valueSet.call(this, $.isFunction(inputData['opts'].onBeforeMask) ? inputData['opts'].onBeforeMask.call(el, value, inputData['opts']) : value);
+                                    $(this).triggerHandler('setvalue.inputmask');
+                                } else {
+                                    valueSet.call(this, value);
+                                }
                             }
                         });
                     }
@@ -938,8 +947,13 @@
                             } else return valueGet.call(this);
                         });
                         npt.__defineSetter__("value", function (value) {
-                            valueSet.call(this, value);
-                            $(this).triggerHandler('setvalue.inputmask');
+                            var inputData = $(this).data('_inputmask');
+                            if (inputData) {
+                                valueSet.call(this, $.isFunction(inputData['opts'].onBeforeMask) ? inputData['opts'].onBeforeMask.call(el, value, inputData['opts']) : value);
+                                $(this).triggerHandler('setvalue.inputmask');
+                            } else {
+                                valueSet.call(this, value);
+                            }
                         });
                     }
                 } else {

+ 3 - 0
js/jquery.inputmask.numeric.extensions.js

@@ -180,6 +180,9 @@ Optional extensions on the jquery.inputmask base
                 processValue = processValue.replace(new RegExp(opts.groupSeparator, "g"), "");
                 processValue = processValue.replace(opts.radixPoint, ".");
                 return isFinite(processValue);
+            },
+            onBeforeMask: function (initialValue, opts) {
+                return isFinite(initialValue) ? initialValue.toString().replace(".", opts.radixPoint) : initialValue;
             }
         },
         'decimal': {