Skip to content

Commit b3d5fe7

Browse files
committed
originalViewValue tracking
1 parent 9476430 commit b3d5fe7

4 files changed

Lines changed: 14 additions & 3 deletions

File tree

Gruntfile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,5 @@ module.exports = function(grunt) {
112112
grunt.registerTask('build', ['check', 'clean', 'concat', 'uglify', 'copy']);
113113
grunt.registerTask('test', ['build', 'karma']);
114114
grunt.registerTask('cov', ['coveralls']);
115+
grunt.registerTask('default', ['build', 'test']);
115116
};

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 avalue 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)