Skip to content

Commit 44da625

Browse files
committed
More cleanup in the validation directive. #8 Exposed methods to hide/show validations.
1 parent 85f291c commit 44da625

File tree

4 files changed

+70
-30
lines changed

4 files changed

+70
-30
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: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,17 @@ angular.module('bootstrap.angular.validation').directive('form', [
5151
delete $formAttributes.ngSubmit;
5252

5353
var preLinkFunction = function($scope, formElement, $attr, formController) {
54-
// Expose a method to manually trigger the validation
55-
formController.$validate = function() {
54+
// Expose a method to manually show the validation state
55+
formController.$showValidation = function() {
5656
formController.$setSubmitted();
57+
// Tell form elements to show validation state
58+
$scope.$broadcast('onBsValidationStateChange', {showValidationState: true});
59+
};
60+
61+
formController.$hideValidation = function () {
62+
formController.$setPristine();
63+
// Tell form elements to hide validation state
64+
$scope.$broadcast('onBsValidationStateChange', {showValidationState: false});
5765
};
5866

5967
formElement.on('submit', function(e) {
@@ -78,12 +86,12 @@ angular.module('bootstrap.angular.validation').directive('form', [
7886
* Do not show validation errors once the form gets submitted. You can still display the
7987
* validation errors after form submission by calling '$setSubmitted' in your form controller.
8088
*/
81-
formController.$setPristine();
89+
formController.$hideValidationState();
8290
});
8391

8492
/**
8593
* Prevent other submit event listener registered via Angular so that we can mark the form with
86-
* the prestine state. Otherwise, that Angular's listener is getting called at the last and is again
94+
* the pristine state. Otherwise, that Angular's listener is getting called at the last and is again
8795
* setting form to the submitted.
8896
*
8997
* https://api.jquery.com/event.stopimmediatepropagation/

0 commit comments

Comments
 (0)