Skip to content

Commit

Permalink
originalViewValue tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
nmccready committed Jul 13, 2016
1 parent 9476430 commit b3d5fe7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,5 @@ module.exports = function(grunt) {
grunt.registerTask('build', ['check', 'clean', 'concat', 'uglify', 'copy']);
grunt.registerTask('test', ['build', 'karma']);
grunt.registerTask('cov', ['coveralls']);
grunt.registerTask('default', ['build', 'test']);
};
7 changes: 6 additions & 1 deletion dist/angular-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,10 @@ angular.module('validation.directive', ['validation.provider']);
*/
var uid = ctrl.validationId = guid();

/**
* to have avalue to rollback to
*/
var originalViewValue = null;

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

$timeout(function() {
ctrl.$setViewValue('');
ctrl.$setViewValue(originalViewValue);
ctrl.$setPristine();
ctrl.$setValidity(ctrl.$name, undefined);
ctrl.$render();
Expand Down Expand Up @@ -783,6 +787,7 @@ angular.module('validation.directive', ['validation.provider']);
*/
if (ctrl.$pristine && ctrl.$viewValue) {
// has value when initial
originalViewValue = ctrl.$viewValue || '';
ctrl.$setViewValue(ctrl.$viewValue);
} else if (ctrl.$pristine) {
// Don't validate form when the input is clean(pristine)
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-validation.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/validator.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@
*/
var uid = ctrl.validationId = guid();

/**
* to have avalue to rollback to
*/
var originalViewValue = null;

/**
* Set initial validity to undefined if no boolean value is transmitted
Expand Down Expand Up @@ -309,7 +313,7 @@
watch();

$timeout(function() {
ctrl.$setViewValue('');
ctrl.$setViewValue(originalViewValue);
ctrl.$setPristine();
ctrl.$setValidity(ctrl.$name, undefined);
ctrl.$render();
Expand Down Expand Up @@ -405,6 +409,7 @@
*/
if (ctrl.$pristine && ctrl.$viewValue) {
// has value when initial
originalViewValue = ctrl.$viewValue || '';
ctrl.$setViewValue(ctrl.$viewValue);
} else if (ctrl.$pristine) {
// Don't validate form when the input is clean(pristine)
Expand Down

0 comments on commit b3d5fe7

Please sign in to comment.