Skip to content

Commit d97e9f3

Browse files
committed
Handling one edge condition when parent element is not available. By default hiding errors after form submission.
1 parent e24a7e1 commit d97e9f3

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

dist/bootstrap-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/directives/form.directive.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ angular.module("bootstrap.angular.validation").directive("form", ["$parse", "$ro
6666
var submitHandler = $parse(ngSubmit);
6767
$scope.$apply(function() {
6868
submitHandler($scope, {$event: e});
69+
70+
/*
71+
* Do not show validation errors once the form gets submitted. You can still display the
72+
* validation errors after form submission by calling "$setSubmitted" in your form controller.
73+
*/
74+
formController.$setPrisiting();
6975
});
7076

7177
/**

src/directives/validation.directive.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ angular.module("bootstrap.angular.validation").directive("bsValidation", ["$inte
4242
// Search for an attribute "form-group" if the class ".form-group" is not available
4343
if (!formGroupElement || formGroupElement.length === 0) {
4444
formGroupElement = $element.parents("[form-group]");
45+
46+
// If we still don't find any element
47+
if (!formGroupElement || formGroupElement.length === 0) {
48+
// Then do not execute the directive at all
49+
return;
50+
}
4551
}
4652

4753
/*

0 commit comments

Comments
 (0)