Browse Source

fix delete/backspace in decimal extension

Robin Herbots 11 years ago
parent
commit
3726d967dc

+ 1 - 1
bower.json

@@ -1,6 +1,6 @@
 {
     "name": "jquery.inputmask",
-    "version": "2.5.0",
+    "version": "2.5.1",
     "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 = 2
 build.minor = 5
-build.revision = 0
+build.revision = 1
 
 target = jquery.inputmask.bundle.js
 target.min = jquery.inputmask.bundle.min.js

BIN
dist/jQuery.InputMask.2.5.0.nupkg


BIN
dist/jQuery.InputMask.2.5.1.nupkg


+ 30 - 27
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: 2.5.0
+* Version: 2.5.1
 */
 
 (function ($) {
@@ -227,10 +227,12 @@
         var msie1x = typeof ScriptEngineMajorVersion === "function"
                         ? ScriptEngineMajorVersion() //IE11 detection
                         : new Function("/*@cc_on return @_jscript_version; @*/")() >= 10, //conditional compilation from mickeysoft trick
-            iphone = navigator.userAgent.match(new RegExp("iphone", "i")) !== null,
-            android = navigator.userAgent.match(new RegExp("android.*safari.*", "i")) !== null,
-            androidchrome = navigator.userAgent.match(new RegExp("android.*chrome.*", "i")) !== null,
-            androidfirefox = navigator.userAgent.match(new RegExp("android.*firefox.*", "i")) !== null,
+                        ua = navigator.userAgent,
+            iphone = ua.match(new RegExp("iphone", "i")) !== null,
+            android = ua.match(new RegExp("android.*safari.*", "i")) !== null,
+            androidchrome = ua.match(new RegExp("android.*chrome.*", "i")) !== null,
+            androidfirefox = ua.match(new RegExp("android.*firefox.*", "i")) !== null,
+            kindle = /Kindle/i.test(ua) || /Silk/i.test(ua) || /KFTT/i.test(ua) || /KFOT/i.test(ua) || /KFJWA/i.test(ua) || /KFJWI/i.test(ua) || /KFSOWI/i.test(ua) || /KFTHWA/i.test(ua) || /KFTHWI/i.test(ua) || /KFAPWA/i.test(ua) || /KFAPWI/i.test(ua),
             PasteEventType = isInputEventSupported('paste') ? 'paste' : isInputEventSupported('input') ? 'input' : "propertychange";
 
         //if (androidchrome) {
@@ -625,7 +627,7 @@
                     if (opts.insertMode == false && begin == end) end++; //set visualization for insert/overwrite mode
                     if (npt.setSelectionRange) {
                         npt.selectionStart = begin;
-                        npt.selectionEnd = android ? begin : end;
+                        npt.selectionEnd = end;
 
                     } else if (npt.createTextRange) {
                         range = npt.createTextRange();
@@ -1182,17 +1184,15 @@
                 }, 0);
             }
 
+            //not used - attempt to support android 
             function mobileInputEvent(e) {
                 var input = this, $input = $(input);
-				input.focus();
 
                 //backspace in chrome32 only fires input event - detect & treat
                 var caretPos = caret(input),
                     currentValue = input._valueGet();
-                    
-                console.log(currentValue);
+
                 currentValue = currentValue.replace(new RegExp("(" + escapeRegex(getActiveBufferTemplate().join('')) + ")*"), "");
-                console.log(currentValue);    
                 //correct caretposition for chrome
                 if (caretPos.begin > currentValue.length) {
                     caret(input, currentValue.length);
@@ -1385,19 +1385,21 @@
 
                     // as the other inputevents aren't reliable for the moment we only base on the input event
                     // needs follow-up
-                    if (android || androidfirefox || androidchrome) {
-                        $el.attr("autocomplete","off")
-                        .attr("autocorrect","off")
-                        .attr("autocapitalize","off")
-                        .attr("spellcheck",false);
-                    
-                        $el.unbind("keydown.inputmask", keydownEvent
-                         	).unbind("keypress.inputmask", keypressEvent
-                         	).unbind("keyup.inputmask", keyupEvent);
-                        if (PasteEventType == "input") {
-                            $el.unbind(PasteEventType + ".inputmask");
+                    if (android || androidfirefox || androidchrome || kindle) {
+                        $el.attr("autocomplete", "off")
+                        .attr("autocorrect", "off")
+                        .attr("autocapitalize", "off")
+                        .attr("spellcheck", false);
+
+                        if (androidfirefox || kindle) {
+                            $el.unbind("keydown.inputmask", keydownEvent
+                                ).unbind("keypress.inputmask", keypressEvent
+                                ).unbind("keyup.inputmask", keyupEvent);
+                            if (PasteEventType == "input") {
+                                $el.unbind(PasteEventType + ".inputmask");
+                            }
+                            $el.bind("input.inputmask", mobileInputEvent);
                         }
-                        $el.bind("input.inputmask", mobileInputEvent);
                     }
 
                     if (msie1x)
@@ -1697,7 +1699,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: 2.5.0
+Version: 2.5.1
 
 Optional extensions on the jquery.inputmask base
 */
@@ -1819,7 +1821,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: 2.5.0
+Version: 2.5.1
 
 Optional extensions on the jquery.inputmask base
 */
@@ -2307,7 +2309,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: 2.5.0
+Version: 2.5.1
 
 Optional extensions on the jquery.inputmask base
 */
@@ -2426,6 +2428,7 @@ Optional extensions on the jquery.inputmask base
                         //strip groupseparator
                         var escapedGroupSeparator = $.inputmask.escapeRegex.call(this, opts.groupSeparator);
                         bufferStr = bufferStr.replace(new RegExp(escapedGroupSeparator, "g"), '');
+                        if (!strict && bufferStr == "") return false;
 
                         var isValid = opts.regex.number(opts).test(bufferStr);
                         if (!isValid) {
@@ -2484,7 +2487,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: 2.5.0
+Version: 2.5.1
 
 Regex extensions on the jquery.inputmask base
 Allows for using regular expressions as a mask
@@ -2668,7 +2671,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: 2.5.0
+Version: 2.5.1
 
 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
+ 84 - 82
dist/jquery.inputmask.bundle.min.js


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


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


+ 1 - 1
jquery.inputmask.jquery.json

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

+ 21 - 18
js/jquery.inputmask.js

@@ -227,10 +227,12 @@
         var msie1x = typeof ScriptEngineMajorVersion === "function"
                         ? ScriptEngineMajorVersion() //IE11 detection
                         : new Function("/*@cc_on return @_jscript_version; @*/")() >= 10, //conditional compilation from mickeysoft trick
-            iphone = navigator.userAgent.match(new RegExp("iphone", "i")) !== null,
-            android = navigator.userAgent.match(new RegExp("android.*safari.*", "i")) !== null,
-            androidchrome = navigator.userAgent.match(new RegExp("android.*chrome.*", "i")) !== null,
-            androidfirefox = navigator.userAgent.match(new RegExp("android.*firefox.*", "i")) !== null,
+                        ua = navigator.userAgent,
+            iphone = ua.match(new RegExp("iphone", "i")) !== null,
+            android = ua.match(new RegExp("android.*safari.*", "i")) !== null,
+            androidchrome = ua.match(new RegExp("android.*chrome.*", "i")) !== null,
+            androidfirefox = ua.match(new RegExp("android.*firefox.*", "i")) !== null,
+            kindle = /Kindle/i.test(ua) || /Silk/i.test(ua) || /KFTT/i.test(ua) || /KFOT/i.test(ua) || /KFJWA/i.test(ua) || /KFJWI/i.test(ua) || /KFSOWI/i.test(ua) || /KFTHWA/i.test(ua) || /KFTHWI/i.test(ua) || /KFAPWA/i.test(ua) || /KFAPWI/i.test(ua),
             PasteEventType = isInputEventSupported('paste') ? 'paste' : isInputEventSupported('input') ? 'input' : "propertychange";
 
         //if (androidchrome) {
@@ -1189,7 +1191,7 @@
                 //backspace in chrome32 only fires input event - detect & treat
                 var caretPos = caret(input),
                     currentValue = input._valueGet();
-                    
+
                 currentValue = currentValue.replace(new RegExp("(" + escapeRegex(getActiveBufferTemplate().join('')) + ")*"), "");
                 //correct caretposition for chrome
                 if (caretPos.begin > currentValue.length) {
@@ -1383,20 +1385,21 @@
 
                     // as the other inputevents aren't reliable for the moment we only base on the input event
                     // needs follow-up
-                    if (android || androidfirefox || androidchrome) {
-                        $el.attr("autocomplete","off")
-                        .attr("autocorrect","off")
-                        .attr("autocapitalize","off")
-                        .attr("spellcheck",false);
-                    /*
-                        $el.unbind("keydown.inputmask", keydownEvent
-                         	).unbind("keypress.inputmask", keypressEvent
-                         	).unbind("keyup.inputmask", keyupEvent);
-                        if (PasteEventType == "input") {
-                            $el.unbind(PasteEventType + ".inputmask");
+                    if (android || androidfirefox || androidchrome || kindle) {
+                        $el.attr("autocomplete", "off")
+                        .attr("autocorrect", "off")
+                        .attr("autocapitalize", "off")
+                        .attr("spellcheck", false);
+
+                        if (androidfirefox || kindle) {
+                            $el.unbind("keydown.inputmask", keydownEvent
+                                ).unbind("keypress.inputmask", keypressEvent
+                                ).unbind("keyup.inputmask", keyupEvent);
+                            if (PasteEventType == "input") {
+                                $el.unbind(PasteEventType + ".inputmask");
+                            }
+                            $el.bind("input.inputmask", mobileInputEvent);
                         }
-                        $el.bind("input.inputmask", mobileInputEvent);
-                    */
                     }
 
                     if (msie1x)

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

@@ -122,6 +122,7 @@ Optional extensions on the jquery.inputmask base
                         //strip groupseparator
                         var escapedGroupSeparator = $.inputmask.escapeRegex.call(this, opts.groupSeparator);
                         bufferStr = bufferStr.replace(new RegExp(escapedGroupSeparator, "g"), '');
+                        if (!strict && bufferStr == "") return false;
 
                         var isValid = opts.regex.number(opts).test(bufferStr);
                         if (!isValid) {

+ 42 - 0
qunit/tests.js

@@ -1211,6 +1211,48 @@ test("inputmask - Multiple inputs masked, Integer mask doesn't allow typing - #4
     $("#testmask2").remove();
 });
 
+test("decimal alias with groupseparator delete - YoussefTaghlabi", function () {
+    $('body').append('<input type="text" id="testmask" />');
+    $("#testmask").inputmask("decimal", { 
+                radixPoint: ".", 
+                groupSeparator: ",",
+                groupSize: 3,
+                digits: 2,
+                autoGroup: true,
+                allowPlus: false,
+                allowMinus: true
+            });
+
+    $("#testmask")[0].focus();
+    $("#testmask").Type("1234567");
+    caret($("#testmask"), 0);   
+	$("#testmask").SendKey(keyCodes.DELETE);
+
+    equal($("#testmask").val(), "234,567", "Result " + $("#testmask").val());
+    $("#testmask").remove();
+});
+
+test("decimal alias with groupseparator backspace - YoussefTaghlabi", function () {
+    $('body').append('<input type="text" id="testmask" />');
+    $("#testmask").inputmask("decimal", { 
+                radixPoint: ".", 
+                groupSeparator: ",",
+                groupSize: 3,
+                digits: 2,
+                autoGroup: true,
+                allowPlus: false,
+                allowMinus: true
+            });
+
+    $("#testmask")[0].focus();
+    $("#testmask").Type("1234567");
+    caret($("#testmask"), 1);   
+	$("#testmask").SendKey(keyCodes.BACKSPACE);
+
+    equal($("#testmask").val(), "234,567", "Result " + $("#testmask").val());
+    $("#testmask").remove();
+});
+
 module("Direction RTL");
 test("inputmask(\"999.999.999\") - delete 2nd with backspace, continue the mask", function () {
     $('body').append('<input type="text" id="testmask" dir="rtl" />');