Skip to content

Commit

Permalink
toggle has-error on parent form-group with $validationProvider valid/…
Browse files Browse the repository at this point in the history
…invalid callbacks
  • Loading branch information
tb committed Feb 7, 2015
1 parent a91d778 commit 1b9d527
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ $validationProvider.setErrorHTML(function (msg) {

You can add the bootstrap class `.has-success` in a similar fashion.

To toggle `.has-error` class on bootstrap `.form-group` wrapper for labels and controls, add:

```javascript
angular.extend($validationProvider, {
validCallback: function (element){
$(element).parents('.form-group:first').removeClass('has-error');
},
invalidCallback: function (element) {
$(element).parents('.form-group:first').addClass('has-error');
}
});
```

CHANGELOG
=====
Expand Down
2 changes: 2 additions & 0 deletions src/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
}
ctrl.$setValidity(ctrl.$name, true);
if (scope.validCallback) scope.validCallback();
if ($validationProvider.validCallback) $validationProvider.validCallback(element);

return true;
};
Expand Down Expand Up @@ -64,6 +65,7 @@
}
ctrl.$setValidity(ctrl.$name, false);
if (scope.inValidCallback) scope.inValidCallback();
if ($validationProvider.invalidCallback) $validationProvider.invalidCallback(element);

return false;
};
Expand Down
2 changes: 2 additions & 0 deletions src/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@
showErrorMessage: this.showErrorMessage,
checkValid: this.checkValid,
validate: this.validate,
validCallback: this.validCallback,
invalidCallback: this.invalidCallback,
reset: this.reset
};
}
Expand Down

0 comments on commit 1b9d527

Please sign in to comment.