Skip to content

Commit 1b9d527

Browse files
committed
toggle has-error on parent form-group with $validationProvider valid/invalid callbacks
1 parent a91d778 commit 1b9d527

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,18 @@ $validationProvider.setErrorHTML(function (msg) {
122122

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

125+
To toggle `.has-error` class on bootstrap `.form-group` wrapper for labels and controls, add:
126+
127+
```javascript
128+
angular.extend($validationProvider, {
129+
validCallback: function (element){
130+
$(element).parents('.form-group:first').removeClass('has-error');
131+
},
132+
invalidCallback: function (element) {
133+
$(element).parents('.form-group:first').addClass('has-error');
134+
}
135+
});
136+
```
125137

126138
CHANGELOG
127139
=====

src/directive.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
}
3434
ctrl.$setValidity(ctrl.$name, true);
3535
if (scope.validCallback) scope.validCallback();
36+
if ($validationProvider.validCallback) $validationProvider.validCallback(element);
3637

3738
return true;
3839
};
@@ -64,6 +65,7 @@
6465
}
6566
ctrl.$setValidity(ctrl.$name, false);
6667
if (scope.inValidCallback) scope.inValidCallback();
68+
if ($validationProvider.invalidCallback) $validationProvider.invalidCallback(element);
6769

6870
return false;
6971
};

src/provider.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@
265265
showErrorMessage: this.showErrorMessage,
266266
checkValid: this.checkValid,
267267
validate: this.validate,
268+
validCallback: this.validCallback,
269+
invalidCallback: this.invalidCallback,
268270
reset: this.reset
269271
};
270272
}

0 commit comments

Comments
 (0)