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

Commit 7cdb4b5

Browse files
Merge pull request #134 from RafaelTaranto/master
Fix issue where $invalid was preserved on blur event - #118
2 parents f730527 + b0b527d commit 7cdb4b5

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/mask.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,10 @@ angular.module('ui.mask', [])
414414
valueMasked = '';
415415
iElement.val('');
416416
scope.$apply(function() {
417-
//don't call $setViewValue to avoid changing $pristine state.
418-
controller.$viewValue = '';
417+
//only $setViewValue when not $pristine to avoid changing $pristine state.
418+
if (!controller.$pristine) {
419+
controller.$setViewValue('');
420+
}
419421
});
420422
}
421423
}

test/maskSpec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,16 @@ describe("uiMask", function () {
687687
expect(input.val()).toBe("");
688688
expect(input.attr("placeholder")).toBe("PLACEHOLDER");
689689
});
690+
691+
it("should not preserve $invalid on blur event", function() {
692+
var form = compileElement(formHtml);
693+
var input = form.find("input");
694+
scope.$apply("x = ''");
695+
scope.$apply("mask = '(A) * 9'");
696+
input.val("a").triggerHandler("input");
697+
input.triggerHandler("blur");
698+
expect(scope.test.input.$invalid).toBe(false);
699+
});
690700
});
691701

692702
describe("Configuration Provider", function() {

0 commit comments

Comments
 (0)