Skip to content

Commit f7c9cba

Browse files
committed
Making sure we only show optional portion of input when we've filled a placeholder
Fixes #63
1 parent 08b4ac9 commit f7c9cba

File tree

5 files changed

+90
-77
lines changed

5 files changed

+90
-77
lines changed

dist/jquery.maskedinput.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
clearBuffer(i + 1, len);
144144
break;
145145
}
146-
} else buffer[i] === test.charAt(pos) && i !== partialPosition && (pos++, lastMatch = i);
146+
} else buffer[i] === test.charAt(pos) && i !== partialPosition && (pos++, partialPosition > i && (lastMatch = i));
147147
return allow ? writeBuffer() : partialPosition > lastMatch + 1 ? settings.autoclear || buffer.join("") === defaultBuffer ? (input.val() && input.val(""),
148148
clearBuffer(0, len)) : writeBuffer() : (writeBuffer(), input.val(input.val().substring(0, lastMatch + 1))),
149149
partialPosition ? i : firstNonMaskPos;

dist/jquery.maskedinput.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/Focus.Spec.js

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -144,77 +144,3 @@ feature("Leaving A Masked Input",function(){
144144
});
145145
});
146146
});
147-
148-
feature("Optional marker",function(){
149-
scenario("Placeholders not filled to marker",function(){
150-
given("a mask with an optional marker",function(){
151-
input.mask("99?99");
152-
});
153-
when("typing one character and leaving",function(){
154-
input.mashKeys("1").blur();
155-
});
156-
then("value should be empty",function(){
157-
expect(input).toHaveValue("");
158-
});
159-
});
160-
161-
scenario("Placeholders not filled to marker and autoclear = false", function() {
162-
given("a mask with an optional marker",function(){
163-
input.mask("99?99", { autoclear: false });
164-
});
165-
when("typing one character and leaving",function(){
166-
input.mashKeys("1").blur();
167-
});
168-
then("value should be empty",function(){
169-
expect(input).toHaveValue("1___");
170-
});
171-
});
172-
173-
scenario("Placeholders filled to marker",function(){
174-
given("a mask with an optional marker",function(){
175-
input.mask("99?99");
176-
});
177-
when("typing two characters and leaving",function(){
178-
input.mashKeys("12").blur();
179-
});
180-
then("value should remain",function(){
181-
expect(input).toHaveValue("12");
182-
});
183-
});
184-
185-
scenario("Placeholders filled to marker and autoclear = false", function() {
186-
given("a mask with an optional marker",function(){
187-
input.mask("99?99", { autoclear: false });
188-
});
189-
when("typing two characters and leaving",function(){
190-
input.mashKeys("12").blur();
191-
});
192-
then("value should remain",function(){
193-
expect(input).toHaveValue("12");
194-
});
195-
});
196-
197-
scenario("Placeholders filled, one marker filled, and autoclear = false", function() {
198-
given("a mask with an optional marker",function(){
199-
input.mask("99?99", { autoclear: false });
200-
});
201-
when("typing three characters and leaving",function(){
202-
input.mashKeys("123").blur();
203-
});
204-
then("value should remain",function(){
205-
expect(input).toHaveValue("123");
206-
});
207-
});
208-
209-
scenario("Placeholders and markers filled, and autoclear = false", function() {
210-
given("a mask with an optional marker",function(){
211-
input.mask("99?99", { autoclear: false });
212-
});
213-
when("typing four characters and leaving",function(){
214-
input.mashKeys("1234").blur();
215-
});
216-
then("value should remain",function(){
217-
expect(input).toHaveValue("1234");
218-
});
219-
});
220-
});

spec/Optional.Spec.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
feature("Optional marker",function(){
2+
scenario("Placeholders not filled to marker",function(){
3+
given("a mask with an optional marker",function(){
4+
input.mask("99?99");
5+
});
6+
when("typing one character and leaving",function(){
7+
input.mashKeys("1").blur();
8+
});
9+
then("value should be empty",function(){
10+
expect(input).toHaveValue("");
11+
});
12+
});
13+
14+
scenario("Placeholders not filled to marker and autoclear = false", function() {
15+
given("a mask with an optional marker",function(){
16+
input.mask("99?99", { autoclear: false });
17+
});
18+
when("typing one character and leaving",function(){
19+
input.mashKeys("1").blur();
20+
});
21+
then("value should be empty",function(){
22+
expect(input).toHaveValue("1___");
23+
});
24+
});
25+
26+
scenario("Placeholders filled to marker",function(){
27+
given("a mask with an optional marker",function(){
28+
input.mask("99?99");
29+
});
30+
when("typing two characters and leaving",function(){
31+
input.mashKeys("12").blur();
32+
});
33+
then("value should remain",function(){
34+
expect(input).toHaveValue("12");
35+
});
36+
});
37+
38+
scenario("Placeholders filled to marker with literals after",function(){
39+
given("a mask with an optional marker and literals",function(){
40+
input.mask("99!? x 99");
41+
});
42+
when("typing two characters and leaving",function(){
43+
input.mashKeys("12").blur();
44+
});
45+
then("value should remain",function(){
46+
expect(input).toHaveValue("12!");
47+
});
48+
});
49+
50+
scenario("Placeholders filled to marker and autoclear = false", function() {
51+
given("a mask with an optional marker",function(){
52+
input.mask("99?99", { autoclear: false });
53+
});
54+
when("typing two characters and leaving",function(){
55+
input.mashKeys("12").blur();
56+
});
57+
then("value should remain",function(){
58+
expect(input).toHaveValue("12");
59+
});
60+
});
61+
62+
scenario("Placeholders filled, one marker filled, and autoclear = false", function() {
63+
given("a mask with an optional marker",function(){
64+
input.mask("99?99", { autoclear: false });
65+
});
66+
when("typing three characters and leaving",function(){
67+
input.mashKeys("123").blur();
68+
});
69+
then("value should remain",function(){
70+
expect(input).toHaveValue("123");
71+
});
72+
});
73+
74+
scenario("Placeholders and markers filled, and autoclear = false", function() {
75+
given("a mask with an optional marker",function(){
76+
input.mask("99?99", { autoclear: false });
77+
});
78+
when("typing four characters and leaving",function(){
79+
input.mashKeys("1234").blur();
80+
});
81+
then("value should remain",function(){
82+
expect(input).toHaveValue("1234");
83+
});
84+
});
85+
});

src/jquery.maskedinput.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,9 @@ $.fn.extend({
345345
}
346346
} else if (buffer[i] === test.charAt(pos) && i !== partialPosition) {
347347
pos++;
348-
lastMatch = i;
348+
if( i < partialPosition){
349+
lastMatch = i;
350+
}
349351
}
350352
}
351353
if (allow) {

0 commit comments

Comments
 (0)