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

Commit b0b527d

Browse files
stconsultoriaRafaelTaranto
authored andcommitted
Fix issue where $invalid was preserved on blur event with test
1 parent 6c7b72d commit b0b527d

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
@@ -410,8 +410,10 @@ angular.module('ui.mask', [])
410410
valueMasked = '';
411411
iElement.val('');
412412
scope.$apply(function() {
413-
//don't call $setViewValue to avoid changing $pristine state.
414-
controller.$viewValue = '';
413+
//only $setViewValue when not $pristine to avoid changing $pristine state.
414+
if (!controller.$pristine) {
415+
controller.$setViewValue('');
416+
}
415417
});
416418
}
417419
}

test/maskSpec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,16 @@ describe("uiMask", function () {
676676
expect(input.val()).toBe("");
677677
expect(input.attr("placeholder")).toBe("PLACEHOLDER");
678678
});
679+
680+
it("should not preserve $invalid on blur event", function() {
681+
var form = compileElement(formHtml);
682+
var input = form.find("input");
683+
scope.$apply("x = ''");
684+
scope.$apply("mask = '(A) * 9'");
685+
input.val("a").triggerHandler("input");
686+
input.triggerHandler("blur");
687+
expect(scope.test.input.$invalid).toBe(false);
688+
});
679689
});
680690

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

0 commit comments

Comments
 (0)