Skip to content

Commit ab0262c

Browse files
committed
Preventing page reload after form submission.
1 parent d48cc04 commit ab0262c

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ angular.module("bootstrap.angular.validation").directive("form", ["$parse", "$ro
5555
};
5656

5757
formElement.on("submit", function(e) {
58+
e.preventDefault();
59+
5860
// If any of the form element has not passed the validation
5961
if (formController.$invalid) {
6062
// Then focus the first invalid element
@@ -67,6 +69,9 @@ angular.module("bootstrap.angular.validation").directive("form", ["$parse", "$ro
6769
$scope.$apply(function() {
6870
submitHandler($scope, {$event: e});
6971

72+
formController.$commitViewValue();
73+
formController.$setSubmitted();
74+
7075
/*
7176
* Do not show validation errors once the form gets submitted. You can still display the
7277
* validation errors after form submission by calling "$setSubmitted" in your form controller.

0 commit comments

Comments
 (0)