Browse Source

fix checkval #379

Robin Herbots 12 years ago
parent
commit
00bd06908d

+ 1 - 1
build.properties

@@ -7,7 +7,7 @@ distdir = dist
 
 
 build.major = 2
 build.major = 2
 build.minor = 4
 build.minor = 4
-build.revision = 5
+build.revision = 6
 
 
 target = jquery.inputmask.bundle.js
 target = jquery.inputmask.bundle.js
 target.min = jquery.inputmask.bundle.min.js
 target.min = jquery.inputmask.bundle.min.js

+ 1 - 1
component.json

@@ -1,6 +1,6 @@
 {
 {
     "name": "jquery.inputmask",
     "name": "jquery.inputmask",
-    "version": "2.4.5",
+    "version": "2.4.6",
     "main": "./dist/jquery.inputmask.bundle.js",
     "main": "./dist/jquery.inputmask.bundle.js",
     "dependencies": {
     "dependencies": {
         "jquery": ">=1.7"
         "jquery": ">=1.7"

BIN
dist/jQuery.InputMask.2.4.5.nupkg


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

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2013 Robin Herbots
 * Copyright (c) 2010 - 2013 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 2.4.5
+* Version: 2.4.6
 */
 */
 
 
 (function ($) {
 (function ($) {
@@ -804,7 +804,7 @@
                     setBufferElement(buffer, pos, getBufferElement(getActiveBufferTemplate(), testPos));
                     setBufferElement(buffer, pos, getBufferElement(getActiveBufferTemplate(), testPos));
                 }
                 }
 
 
-                function checkVal(input, writeOut, strict, nptvl) {
+                function checkVal(input, writeOut, strict, nptvl, intelliCheck) {
                     var inputValue = nptvl != undefined ? nptvl.slice() : truncateInput(input._valueGet()).split('');
                     var inputValue = nptvl != undefined ? nptvl.slice() : truncateInput(input._valueGet()).split('');
 
 
                     $.each(masksets, function (ndx, ms) {
                     $.each(masksets, function (ndx, ms) {
@@ -818,12 +818,14 @@
                     if (writeOut) input._valueSet(""); //initial clear
                     if (writeOut) input._valueSet(""); //initial clear
                     var ml = getMaskLength();
                     var ml = getMaskLength();
                     $.each(inputValue, function (ndx, charCode) {
                     $.each(inputValue, function (ndx, charCode) {
-                        var lvp = getActiveMaskSet()["lastValidPosition"],
-                        pos = lvp == -1 ? ndx : seekNext(lvp);
-
-                        if ($.isArray(opts.mask) || $.inArray(charCode, getActiveBufferTemplate().slice(lvp + 1, pos)) == -1) {
-                            //console.log("trigger " + charCode);
-                            $(input).trigger("_keypress", [true, charCode.charCodeAt(0), writeOut, strict, ndx]);
+                        if(intelliCheck === true) { 
+                        	var p = getActiveMaskSet()["p"], lvp = p == -1 ? p : seekPrevious(p),
+                        	pos = lvp == -1 ? ndx : seekNext(lvp);
+                            if ($.inArray(charCode, getActiveBufferTemplate().slice(lvp + 1, pos)) == -1) {
+                            	$(input).trigger("_keypress", [true, charCode.charCodeAt(0), writeOut, strict, ndx]);
+                        	}
+                        } else {
+                          	$(input).trigger("_keypress", [true, charCode.charCodeAt(0), writeOut, strict, ndx]);
                         }
                         }
                     });
                     });
 
 
@@ -1118,7 +1120,7 @@
                             return true;
                             return true;
                         }
                         }
                         setTimeout(function () {
                         setTimeout(function () {
-                            checkVal(input, true, false);
+                            checkVal(input, true, false, undefined, true);
                             if (isComplete(getActiveBuffer()) === true)
                             if (isComplete(getActiveBuffer()) === true)
                                 $input.trigger("complete");
                                 $input.trigger("complete");
                             $input.click();
                             $input.click();
@@ -1661,7 +1663,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2013 Robin Herbots
 Copyright (c) 2010 - 2013 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 2.4.5
+Version: 2.4.6
 
 
 Optional extensions on the jquery.inputmask base
 Optional extensions on the jquery.inputmask base
 */
 */
@@ -1783,7 +1785,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2012 Robin Herbots
 Copyright (c) 2010 - 2012 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 2.4.5
+Version: 2.4.6
 
 
 Optional extensions on the jquery.inputmask base
 Optional extensions on the jquery.inputmask base
 */
 */
@@ -2267,7 +2269,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2013 Robin Herbots
 Copyright (c) 2010 - 2013 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 2.4.5
+Version: 2.4.6
 
 
 Optional extensions on the jquery.inputmask base
 Optional extensions on the jquery.inputmask base
 */
 */
@@ -2444,7 +2446,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2013 Robin Herbots
 Copyright (c) 2010 - 2013 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 2.4.5
+Version: 2.4.6
 
 
 Regex extensions on the jquery.inputmask base
 Regex extensions on the jquery.inputmask base
 Allows for using regular expressions as a mask
 Allows for using regular expressions as a mask
@@ -2614,7 +2616,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2013 Robin Herbots
 Copyright (c) 2010 - 2013 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 2.4.5
+Version: 2.4.6
 
 
 Phone extension.
 Phone extension.
 When using this extension make sure you specify the correct url to get the masks
 When using this extension make sure you specify the correct url to get the masks

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


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


+ 1 - 1
jquery.inputmask.jquery.json

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

+ 10 - 8
js/jquery.inputmask.js

@@ -804,7 +804,7 @@
                     setBufferElement(buffer, pos, getBufferElement(getActiveBufferTemplate(), testPos));
                     setBufferElement(buffer, pos, getBufferElement(getActiveBufferTemplate(), testPos));
                 }
                 }
 
 
-                function checkVal(input, writeOut, strict, nptvl) {
+                function checkVal(input, writeOut, strict, nptvl, intelliCheck) {
                     var inputValue = nptvl != undefined ? nptvl.slice() : truncateInput(input._valueGet()).split('');
                     var inputValue = nptvl != undefined ? nptvl.slice() : truncateInput(input._valueGet()).split('');
 
 
                     $.each(masksets, function (ndx, ms) {
                     $.each(masksets, function (ndx, ms) {
@@ -818,12 +818,14 @@
                     if (writeOut) input._valueSet(""); //initial clear
                     if (writeOut) input._valueSet(""); //initial clear
                     var ml = getMaskLength();
                     var ml = getMaskLength();
                     $.each(inputValue, function (ndx, charCode) {
                     $.each(inputValue, function (ndx, charCode) {
-                        var lvp = getActiveMaskSet()["lastValidPosition"],
-                        pos = lvp == -1 ? ndx : seekNext(lvp);
-
-                        if ($.isArray(opts.mask) || $.inArray(charCode, getActiveBufferTemplate().slice(lvp + 1, pos)) == -1) {
-                            //console.log("trigger " + charCode);
-                            $(input).trigger("_keypress", [true, charCode.charCodeAt(0), writeOut, strict, ndx]);
+                        if(intelliCheck === true) { 
+                        	var p = getActiveMaskSet()["p"], lvp = p == -1 ? p : seekPrevious(p),
+                        	pos = lvp == -1 ? ndx : seekNext(lvp);
+                            if ($.inArray(charCode, getActiveBufferTemplate().slice(lvp + 1, pos)) == -1) {
+                            	$(input).trigger("_keypress", [true, charCode.charCodeAt(0), writeOut, strict, ndx]);
+                        	}
+                        } else {
+                          	$(input).trigger("_keypress", [true, charCode.charCodeAt(0), writeOut, strict, ndx]);
                         }
                         }
                     });
                     });
 
 
@@ -1118,7 +1120,7 @@
                             return true;
                             return true;
                         }
                         }
                         setTimeout(function () {
                         setTimeout(function () {
-                            checkVal(input, true, false);
+                            checkVal(input, true, false, undefined, true);
                             if (isComplete(getActiveBuffer()) === true)
                             if (isComplete(getActiveBuffer()) === true)
                                 $input.trigger("complete");
                                 $input.trigger("complete");
                             $input.click();
                             $input.click();

+ 53 - 9
qunit/tests.js

@@ -90,6 +90,12 @@ $.fn.Type = function (inputStr) {
     });
     });
 }
 }
 
 
+$.fn.paste = function (inputStr) {
+    var $input = $(this);
+    $input[0]._valueSet(inputStr);
+    $input.trigger('paste');
+}
+
 module("Simple masking");
 module("Simple masking");
 
 
 test("inputmask(\"99-99-99\", { clearMaskOnLostFocus: false}", function () {
 test("inputmask(\"99-99-99\", { clearMaskOnLostFocus: false}", function () {
@@ -444,21 +450,59 @@ test("inputmask(\"mm/yyyy\") ~ value=\"031973\" - disabled input", function () {
     $("#testmask").remove();
     $("#testmask").remove();
 });
 });
 
 
-module("Set value with fn.val");
-test("inputmask(\"decimal\") ~ value=\"123.45\"", function () {
+test("inputmask(\"6703 9999 9999 9999 9\") ~ value=\"6703 1234 5678 9012 3\" - FransVdb", function () {
+    $('body').append('<input type="text" id="testmask" value="6703 1234 5678 9012 3" />');
+    $("#testmask").inputmask("6703 9999 9999 9999 9");
+    equal($("#testmask").val(), "6703 1234 5678 9012 3", "Result " + $("#testmask").val());
+
+    $("#testmask").remove();
+});
+
+test("inputmask(\"6703 9999 9999 9999 9\") ~ type \"6703 1234 5678 9012 3\" + backspace - FransVdb", function () {
     $('body').append('<input type="text" id="testmask" />');
     $('body').append('<input type="text" id="testmask" />');
-    $("#testmask").inputmask("decimal");
-    $("#testmask").val("123.45");
-    equal($("#testmask").val(), "123.45", "Result " + $("#testmask").val());
+    $("#testmask").inputmask("6703 9999 9999 9999 9");
+    $("#testmask")[0].focus();
+    $("#testmask").Type("1234567890123");
+    $("#testmask").SendKey(keyCodes.BACKSPACE);	
+
+    equal($("#testmask").val(), "6703 1234 5678 9012 _", "Result " + $("#testmask").val());
+
+    $("#testmask").remove();
+});
+
+test("inputmask(\"6703 9999 9999 9999 9\") ~ type \"6703670367036\" + backspace - FransVdb", function () {
+    $('body').append('<input type="text" id="testmask" />');
+    $("#testmask").inputmask("6703 9999 9999 9999 9");
+    $("#testmask")[0].focus();
+    $("#testmask").Type("6703670367036");
+    $("#testmask").SendKey(keyCodes.BACKSPACE);	
+
+    equal($("#testmask").val(), "6703 6703 6703 6703 _", "Result " + $("#testmask").val());
 
 
     $("#testmask").remove();
     $("#testmask").remove();
 });
 });
 
 
-test("inputmask(\"+7 (999) 999-99-99\") ~ value=\"+7 (+79114041112___) ___-__-__\"", function () {
+
+module("Paste value");
+asyncTest("inputmask(\"+7 (999) 999-99-99\") ~ paste \"+7 (+79114041112___) ___-__-__\"", function () {
     $('body').append('<input type="text" id="testmask" />');
     $('body').append('<input type="text" id="testmask" />');
     $("#testmask").inputmask("+7 (999) 999-99-99");
     $("#testmask").inputmask("+7 (999) 999-99-99");
-    $("#testmask").val("+7 (+79114041112___) ___-__-__");
-    equal($("#testmask").val(), "+7 (911) 404-11-12", "Result " + $("#testmask").val());
+    $("#testmask").paste("+7 (+79114041112___) ___-__-__");
+    
+    setTimeout(function () {
+	equal($("#testmask").val(), "+7 (911) 404-11-12", "Result " + $("#testmask").val());
+	start();
+	$("#testmask").remove();
+    }, 0);
+
+});
+
+module("Set value with fn.val");
+test("inputmask(\"decimal\") ~ value=\"123.45\"", function () {
+    $('body').append('<input type="text" id="testmask" />');
+    $("#testmask").inputmask("decimal");
+    $("#testmask").val("123.45");
+    equal($("#testmask").val(), "123.45", "Result " + $("#testmask").val());
 
 
     $("#testmask").remove();
     $("#testmask").remove();
 });
 });
@@ -1687,4 +1731,4 @@ test("inputmask(\"*{1,20}@*{1,20}.*{2,6}[.*{2}]\" - email mask", function () {
     equal($("#testmask").val(), "some.body@mail.com", "Result " + $("#testmask").val());
     equal($("#testmask").val(), "some.body@mail.com", "Result " + $("#testmask").val());
 
 
     $("#testmask").remove();
     $("#testmask").remove();
-});
+});

File diff suppressed because it is too large
+ 1732 - 0
qunit/tests.js~