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

Commit

Permalink
Merge pull request #103 from tpeter1985/master
Browse files Browse the repository at this point in the history
Extend directives for revalidating
  • Loading branch information
ghiscoding committed Jan 21, 2016
2 parents 70a0bb6 + 46bca11 commit 7253b76
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/validation-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ angular
var isSubmitted = (!!attrs && attrs.isSubmitted) ? attrs.isSubmitted : false;

// invalid & isDirty, display the error message... if <span> not exist then create it, else udpate the <span> text
if (!_globalOptions.hideErrorUnderInputs && !!attrs && !attrs.isValid && (isSubmitted || self.ctrl.$dirty || self.ctrl.$touched)) {
if (!_globalOptions.hideErrorUnderInputs && !!attrs && !attrs.isValid && (isSubmitted || self.ctrl.$dirty || self.ctrl.$touched || self.ctrl.revalidateCalled)) {
(errorElm.length > 0) ? errorElm.html(errorMsg) : elm.after('<div class="validation validation-' + elmInputName + ' text-danger">' + errorMsg + '</div>');
} else {
errorElm.html(''); // element is pristine or no validation applied, error message has to be blank
Expand Down
20 changes: 20 additions & 0 deletions src/validation-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,26 @@

// attach the onBlur event handler on the element
elm.bind('blur', blurHandler);

// attach the angularValidation.revalidate event handler on the scope
scope.$on('angularValidation.revalidate', function(event, args){
if (args == ctrl.$name)
{
ctrl.revalidateCalled = true;
var value = ctrl.$modelValue;

if (!elm.isValidationCancelled) {
// attempt to validate & run validation callback if user requested it
var validationPromise = attemptToValidate(value);
if(!!_validationCallback) {
commonObj.runValidationCallbackOnPromise(validationPromise, _validationCallback);
}
}
else {
ctrl.$setValidity('validation', true);
}
}
});

//----
// Private functions declaration
Expand Down

0 comments on commit 7253b76

Please sign in to comment.