Skip to content
This repository was archived by the owner on Jan 24, 2019. It is now read-only.

Commit 4e96d0a

Browse files
author
Vinícius Fernandes de Jesus
committed
Support for placeholder when mask has optional characters
1 parent 0ce930d commit 4e96d0a

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

modules/mask/mask.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,15 @@ angular.module('ui.mask', [])
257257
minRequiredLength = 0;
258258

259259
var isOptional = false,
260+
numberOfOptionalCharacters = 0,
260261
splitMask = mask.split('');
261262

262263
angular.forEach(splitMask, function (chr, i){
263264
if (linkOptions.maskDefinitions[chr]) {
264265

265266
maskCaretMap.push(characterCount);
266267

267-
maskPlaceholder += getPlaceholderChar(i);
268+
maskPlaceholder += getPlaceholderChar(i - numberOfOptionalCharacters);
268269
maskPatterns.push(linkOptions.maskDefinitions[chr]);
269270

270271
characterCount++;
@@ -274,6 +275,7 @@ angular.module('ui.mask', [])
274275
}
275276
else if (chr === '?') {
276277
isOptional = true;
278+
numberOfOptionalCharacters++;
277279
}
278280
else {
279281
maskPlaceholder += chr;

modules/mask/test/maskSpec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,13 @@ describe("uiMask", function () {
227227
expect(input.attr("placeholder")).toBe("MM/DD/YYYY");
228228
});
229229

230+
it("should ignore the '?' character", function() {
231+
var placeholderHtml = "<input type=\"text\" ui-mask=\"99/99/9999 ?99:99\" placeholder=\"DD/MM/YYYY HH:mm\" ng-model=\"myDate\">",
232+
input = compileElement(placeholderHtml);
233+
234+
scope.$apply("myDate = ''");
235+
expect(input.attr("placeholder")).toBe("DD/MM/YYYY HH:mm");
236+
});
230237

231238
});
232239

0 commit comments

Comments
 (0)