Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Commit 7090722

Browse files
Rouchelukepfeiffer10
authored andcommitted
Fixes #157 (#159)
* Fixes #157 * Fixes #157 * Fixes #157
1 parent c16fd40 commit 7090722

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

src/mask.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ angular.module('ui.mask', [])
7777
preventBackspace;
7878

7979
var originalIsEmpty = controller.$isEmpty;
80-
controller.$isEmpty = function(value) {
81-
if (maskProcessed) {
82-
return originalIsEmpty(unmaskValue(value || ''));
83-
} else {
84-
return originalIsEmpty(value);
85-
}
86-
};
80+
controller.$isEmpty = function(value) {
81+
if (maskProcessed) {
82+
return originalIsEmpty(unmaskValue(value || ''));
83+
} else {
84+
return originalIsEmpty(value);
85+
}
86+
};
8787

8888
function initialize(maskAttr) {
8989
if (!angular.isDefined(maskAttr)) {
@@ -453,8 +453,21 @@ angular.module('ui.mask', [])
453453
}
454454
}
455455
//Check for different value and trigger change.
456+
//Check for different value and trigger change.
456457
if (value !== prevValue) {
458+
// #157 Fix the bug from the trigger when backspacing exactly on the first letter (emptying the field)
459+
// and then blurring out.
460+
// Angular uses html element and calls setViewValue(element.value.trim()), setting it to the trimmed mask
461+
// when it should be empty
462+
var currentVal = iElement.val();
463+
var isTemporarilyEmpty = value === '' && currentVal && angular.isDefined(iAttrs.uiMaskPlaceholderChar) && iAttrs.uiMaskPlaceholderChar === 'space';
464+
if(isTemporarilyEmpty) {
465+
iElement.val('');
466+
}
457467
triggerChangeEvent(iElement[0]);
468+
if(isTemporarilyEmpty) {
469+
iElement.val(currentVal);
470+
}
458471
}
459472
prevValue = value;
460473
}
@@ -593,7 +606,7 @@ angular.module('ui.mask', [])
593606

594607
// If value has not changed, don't want to call $setViewValue, may be caused by IE raising input event due to placeholder
595608
if (valUnmasked !== valUnmaskedOld)
596-
valAltered = true;
609+
valAltered = true;
597610
}
598611

599612
// Update values

0 commit comments

Comments
 (0)