Browse Source

Input Mask for search fields (partially filled mask) #2425

Robin Herbots 5 years ago
parent
commit
acc1c3b55c

+ 1 - 0
CHANGELOG.md

@@ -5,6 +5,7 @@
 - enhance alternation logic
  
 ### Fixed
+- Input Mask for search fields (partially filled mask) #2425
 - HandleNativePlaceholder function prevents use of dynamic placeholders. #2433
 - '0' getting added unnecessarily if navigating using arrow key for datetime input mask #2289
 - jitmasking ssn #2420

+ 1 - 1
bower.json

@@ -1,6 +1,6 @@
 {
   "name": "inputmask",
-  "version": "5.0.6-beta.22",
+  "version": "5.0.6-beta.23",
   "main": [
 	  "./index.js",
     "./css/inputmask.css"

+ 1 - 1
composer.json

@@ -1,7 +1,7 @@
 {
   "name": "robinherbots/inputmask",
   "description": "Inputmask is a javascript library which creates an input mask.  Inputmask can run against vanilla javascript, jQuery and jqlite.",
-  "version": "5.0.6-beta.22",
+  "version": "5.0.6-beta.23",
   "type": "library",
   "keywords": ["jquery", "plugins", "input", "form", "inputmask", "mask"],
   "homepage": "http://robinherbots.github.io/Inputmask",

File diff suppressed because it is too large
+ 144 - 144
dist/inputmask.js


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


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


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


+ 11 - 8
lib/inputHandling.js

@@ -42,7 +42,7 @@ function clearOptionalTail(buffer) {
 function checkVal(input, writeOut, strict, nptvl, initiatingEvent) {
 	const inputmask = input ? input.inputmask : this,
 		maskset = inputmask.maskset,
-		opts = inputmask.opts,$ = inputmask.dependencyLib;
+		opts = inputmask.opts, $ = inputmask.dependencyLib;
 
 	var inputValue = nptvl.slice(),
 		charCodes = "",
@@ -78,12 +78,13 @@ function checkVal(input, writeOut, strict, nptvl, initiatingEvent) {
 	inputmask.caretPos = {begin: initialNdx};
 
 	var staticMatches = [], prevCaretPos = inputmask.caretPos;
-	inputValue.forEach( function ( charCode, ndx) {
+	inputValue.forEach(function (charCode, ndx) {
 		if (charCode !== undefined) { //inputfallback strips some elements out of the inputarray.  $.each logically presents them as undefined
-			if (maskset.validPositions[ndx] === undefined && inputValue[ndx] === getPlaceholder.call(inputmask, ndx) && isMask.call(inputmask, ndx, true) &&
-				isValid.call(inputmask, ndx, inputValue[ndx], true, undefined, undefined, true) === false) {
-				maskset.p++;
-			} else {
+			/*if (maskset.validPositions[ndx] === undefined && inputValue[ndx] === getPlaceholder.call(inputmask, ndx) && isMask.call(inputmask, ndx, true) &&
+				isValid.call(inputmask, ndx, inputValue[ndx], true, undefined, true, true) === false) {
+				inputmask.caretPos.begin++;
+			} else*/
+			{
 				var keypress = new $.Event("_checkval");
 				keypress.which = charCode.toString().charCodeAt(0);
 				charCodes += charCode;
@@ -109,8 +110,10 @@ function checkVal(input, writeOut, strict, nptvl, initiatingEvent) {
 					inputmask.caretPos = {begin: result.forwardPosition, end: result.forwardPosition};
 					prevCaretPos = inputmask.caretPos;
 				} else {
-					inputmask.caretPos = prevCaretPos;
-				}  //restore the caret position from before the failed validation
+					if (maskset.validPositions[ndx] === undefined && inputValue[ndx] === getPlaceholder.call(inputmask, ndx) && isMask.call(inputmask, ndx, true)) {
+						inputmask.caretPos.begin++;
+					} else inputmask.caretPos = prevCaretPos; //restore the caret position from before the failed validation
+				}
 			}
 		}
 	});

+ 0 - 1
lib/positioning.js

@@ -7,7 +7,6 @@ import {
 	getTestTemplate
 } from "./validation-tests";
 import {checkAlternationMatch} from "./validation";
-import {mask} from "./mask";
 
 export {
 	caret,

+ 0 - 1
lib/validation.js

@@ -268,7 +268,6 @@ function isValid(pos, c, strict, fromIsValid, fromAlternate, validateOnly, fromC
 	const inputmask = this,
 		$ = this.dependencyLib,
 		opts = this.opts,
-		el = inputmask.el,
 		maskset = inputmask.maskset;
 
 	function isSelection(posObj) {

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "inputmask",
-  "version": "5.0.6-beta.22",
+  "version": "5.0.6-beta.23",
   "description": "Inputmask is a javascript library which creates an input mask.  Inputmask can run against vanilla javascript, jQuery and jqlite.",
   "main": "dist/inputmask.js",
   "files": [

+ 1 - 1
qunit/index.js

@@ -14,7 +14,7 @@ Inputmask.extendDefaults({
     inputEventOnly: false
 });
 
-// window.Inputmask = Inputmask; //inject globally for the simulator to detect inputeventonly
+window.Inputmask = Inputmask; //inject globally for the simulator to detect inputeventonly
 
 import tests_alternations from "./tests_alternations";
 import tests_attributes from "./tests_attributes";

+ 15 - 2
qunit/tests_initialvalue.js

@@ -113,7 +113,8 @@ export default function (qunit, Inputmask) {
 	qunit.test("inputmask(\"6703 9999 9999 9999 9\") ~ value=\"6703 1234 5678 9012 3\" - FransVdb", function (assert) {
 		var $fixture = $("#qunit-fixture");
 		$fixture.append("<input type=\"text\" id=\"testmask\" value=\"6703 1234 5678 9012 3\" />");
-		Inputmask("6703 9999 9999 9999 9");
+		var testmask = document.getElementById("testmask");
+		Inputmask("6703 9999 9999 9999 9").mask(testmask);
 		assert.equal(testmask.value, "6703 1234 5678 9012 3", "Result " + testmask.value);
 	});
 
@@ -268,4 +269,16 @@ export default function (qunit, Inputmask) {
 			done();
 		}, 5);
 	});
-};
+
+	qunit.test("partial filled searchfield - docwaremm", function (assert) {
+		var done = assert.async(),
+			$fixture = $("#qunit-fixture");
+		$fixture.append("<input type=\"text\" id=\"testmask\" value=\"___-__6789-9\" />");
+		var testmask = document.getElementById("testmask");
+		Inputmask("999-999999-9").mask(testmask);
+		setTimeout(function () {
+			assert.equal(testmask.value, "___-__6789-9", "Result " + testmask.value);
+			done();
+		}, 5);
+	});
+}