Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Nazanin1369 committed Dec 17, 2015
2 parents e894f50 + bf77647 commit 1945b10
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 1 deletion.
21 changes: 21 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,24 @@ scope.validationInvalidHandler = function(message){
displayMessage(message, 'error');
};
```


### **Setup a global valid/invalid/reset callback in config phase**

```javascript
// your module
angular.module('yourApp', ['validation'])
.config(['$validationProvider', function ($validationProvider) {
validationProvider.validCallback = function(element) {
$(element).parents('.validator-container:first').removeClass('has-error').addClass('has-success-tick');
};
validationProvider.invalidCallback = function(element) {
$(element).parents('.validator-container:first').removeClass('has-success-tick').addClass('has-error');
};
validationProvider.resetCallback = function(element) {
$(element).parents('.validator-container:first').removeClass('has-error');
};
}]);
```


9 changes: 9 additions & 0 deletions dist/angular-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@
*/
this.invalidCallback = null;

/**
* Do this function when reset is performed
* @param element
*/
this.resetCallback = null;

/**
* reset the specific form
* @param form
Expand Down Expand Up @@ -286,6 +292,7 @@
validate: this.validate,
validCallback: this.validCallback,
invalidCallback: this.invalidCallback,
resetCallback: this.resetCallback,
reset: this.reset
};
}];
Expand Down Expand Up @@ -574,6 +581,8 @@
ctrl.$render();
if (attrs.messageId) angular.element(document.querySelector('#' + attrs.messageId)).html('');
else element.next().html('');

if ($validationProvider.resetCallback) $validationProvider.resetCallback(element);
});
});

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.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"validator",
"client-side"
],
"main": "./dist/angular-validation.js",
"bugs": "https://github.com/huei90/angular-validation/issues",
"devDependencies": {
"grunt": "~0.4.4",
Expand Down
7 changes: 7 additions & 0 deletions src/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,12 @@
*/
this.invalidCallback = null;

/**
* Do this function when reset is performed
* @param element
*/
this.resetCallback = null;

/**
* reset the specific form
* @param form
Expand Down Expand Up @@ -280,6 +286,7 @@
validate: this.validate,
validCallback: this.validCallback,
invalidCallback: this.invalidCallback,
resetCallback: this.resetCallback,
reset: this.reset
};
}];
Expand Down
2 changes: 2 additions & 0 deletions src/validator.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@
ctrl.$render();
if (attrs.messageId) angular.element(document.querySelector('#' + attrs.messageId)).html('');
else element.next().html('');

if ($validationProvider.resetCallback) $validationProvider.resetCallback(element);
});
});

Expand Down

0 comments on commit 1945b10

Please sign in to comment.