Skip to content

Commit e24a7e1

Browse files
committed
Finally fixed the form pristine/suubmitted state. Now one can easily set the form to pristine state after submission. #3
1 parent 6a1c698 commit e24a7e1

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
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: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,17 @@ angular.module("bootstrap.angular.validation").directive("form", ["$parse", "$ro
6666
var submitHandler = $parse(ngSubmit);
6767
$scope.$apply(function() {
6868
submitHandler($scope, {$event: e});
69-
formController.$setPristine();
7069
});
7170

72-
return true;
71+
/**
72+
* Prevent other submit event listener registered via Angular so that we can mark the form with
73+
* the prestine state. Otherwise, that Angular's listener is getting called at the last and is again
74+
* setting form to the submitted.
75+
*
76+
* https://api.jquery.com/event.stopimmediatepropagation/
77+
*/
78+
e.stopImmediatePropagation();
79+
return false;
7380
});
7481
};
7582

src/directives/validation.directive.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ angular.module("bootstrap.angular.validation").directive("bsValidation", ["$inte
7777
* Do not show or hide error for current element don't have any validation errors or has validation
7878
* error but user has not attempted to submit the form yet.
7979
*/
80-
if (!ngFormController.$submitted || !ngModelController.$invalid || ngModelController.$pristine) {
80+
if (!ngFormController.$submitted || !ngModelController.$invalid) {
8181
formGroupElement.removeClass("has-error");
8282

8383
if (formGroupElement.length > 0) {

0 commit comments

Comments
 (0)