Skip to content

Commit f26019c

Browse files
author
Huei Tan
authored
Merge pull request #223 from nmccready/originalValueTracking
Track originalViewValue
2 parents f87a51c + 5d9085d commit f26019c

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

dist/angular-validation.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,10 @@ angular.module('validation.directive', ['validation.provider']);
646646
*/
647647
var uid = ctrl.validationId = guid();
648648

649+
/**
650+
* to have avalue to rollback to
651+
*/
652+
var originalViewValue = null;
649653

650654
/**
651655
* Set initial validity to undefined if no boolean value is transmitted
@@ -687,7 +691,7 @@ angular.module('validation.directive', ['validation.provider']);
687691
watch();
688692

689693
$timeout(function() {
690-
ctrl.$setViewValue('');
694+
ctrl.$setViewValue(originalViewValue);
691695
ctrl.$setPristine();
692696
ctrl.$setValidity(ctrl.$name, undefined);
693697
ctrl.$render();
@@ -783,6 +787,7 @@ angular.module('validation.directive', ['validation.provider']);
783787
*/
784788
if (ctrl.$pristine && ctrl.$viewValue) {
785789
// has value when initial
790+
originalViewValue = ctrl.$viewValue || '';
786791
ctrl.$setViewValue(ctrl.$viewValue);
787792
} else if (ctrl.$pristine) {
788793
// Don't validate form when the input is clean(pristine)

dist/angular-validation.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.

src/validator.directive.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@
268268
*/
269269
var uid = ctrl.validationId = guid();
270270

271+
/**
272+
* to have a value to rollback to
273+
*/
274+
var originalViewValue = null;
271275

272276
/**
273277
* Set initial validity to undefined if no boolean value is transmitted
@@ -309,7 +313,7 @@
309313
watch();
310314

311315
$timeout(function() {
312-
ctrl.$setViewValue('');
316+
ctrl.$setViewValue(originalViewValue);
313317
ctrl.$setPristine();
314318
ctrl.$setValidity(ctrl.$name, undefined);
315319
ctrl.$render();
@@ -405,6 +409,7 @@
405409
*/
406410
if (ctrl.$pristine && ctrl.$viewValue) {
407411
// has value when initial
412+
originalViewValue = ctrl.$viewValue || '';
408413
ctrl.$setViewValue(ctrl.$viewValue);
409414
} else if (ctrl.$pristine) {
410415
// Don't validate form when the input is clean(pristine)

0 commit comments

Comments
 (0)