Skip to content
This repository was archived by the owner on Jul 1, 2020. It is now read-only.

Commit 7253b76

Browse files
committed
Merge pull request #103 from tpeter1985/master
Extend directives for revalidating
2 parents 70a0bb6 + 46bca11 commit 7253b76

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/validation-common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ angular
482482
var isSubmitted = (!!attrs && attrs.isSubmitted) ? attrs.isSubmitted : false;
483483

484484
// invalid & isDirty, display the error message... if <span> not exist then create it, else udpate the <span> text
485-
if (!_globalOptions.hideErrorUnderInputs && !!attrs && !attrs.isValid && (isSubmitted || self.ctrl.$dirty || self.ctrl.$touched)) {
485+
if (!_globalOptions.hideErrorUnderInputs && !!attrs && !attrs.isValid && (isSubmitted || self.ctrl.$dirty || self.ctrl.$touched || self.ctrl.revalidateCalled)) {
486486
(errorElm.length > 0) ? errorElm.html(errorMsg) : elm.after('<div class="validation validation-' + elmInputName + ' text-danger">' + errorMsg + '</div>');
487487
} else {
488488
errorElm.html(''); // element is pristine or no validation applied, error message has to be blank

src/validation-directive.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,26 @@
8787

8888
// attach the onBlur event handler on the element
8989
elm.bind('blur', blurHandler);
90+
91+
// attach the angularValidation.revalidate event handler on the scope
92+
scope.$on('angularValidation.revalidate', function(event, args){
93+
if (args == ctrl.$name)
94+
{
95+
ctrl.revalidateCalled = true;
96+
var value = ctrl.$modelValue;
97+
98+
if (!elm.isValidationCancelled) {
99+
// attempt to validate & run validation callback if user requested it
100+
var validationPromise = attemptToValidate(value);
101+
if(!!_validationCallback) {
102+
commonObj.runValidationCallbackOnPromise(validationPromise, _validationCallback);
103+
}
104+
}
105+
else {
106+
ctrl.$setValidity('validation', true);
107+
}
108+
}
109+
});
90110

91111
//----
92112
// Private functions declaration

0 commit comments

Comments
 (0)