From 06bf4adc856cd4733d349f88c83393788c805c70 Mon Sep 17 00:00:00 2001 From: Timo Peter Date: Thu, 21 Jan 2016 13:50:54 +0100 Subject: [PATCH 1/2] Extend directives for revalidating Extending the package make a revalidation possible for directives. --- src/validation-common.js | 2 +- src/validation-directive.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/validation-common.js b/src/validation-common.js index 4e71c53..5126ddd 100644 --- a/src/validation-common.js +++ b/src/validation-common.js @@ -482,7 +482,7 @@ angular var isSubmitted = (!!attrs && attrs.isSubmitted) ? attrs.isSubmitted : false; // invalid & isDirty, display the error message... if not exist then create it, else udpate the 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('
' + errorMsg + '
'); } else { errorElm.html(''); // element is pristine or no validation applied, error message has to be blank diff --git a/src/validation-directive.js b/src/validation-directive.js index 82d6049..3b6f4e1 100644 --- a/src/validation-directive.js +++ b/src/validation-directive.js @@ -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, 0); + if(!!_validationCallback) { + commonObj.runValidationCallbackOnPromise(validationPromise, _validationCallback); + } + } + else { + ctrl.$setValidity('validation', true); + } + } + }); //---- // Private functions declaration From 46bca1183ec05128f95edf23d03df9f665c407b5 Mon Sep 17 00:00:00 2001 From: Timo Peter Date: Thu, 21 Jan 2016 17:15:26 +0100 Subject: [PATCH 2/2] Extend Revalidate Function The Revalidate functionality now regards the "debounce" configuration. --- src/validation-directive.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/validation-directive.js b/src/validation-directive.js index 3b6f4e1..41f977b 100644 --- a/src/validation-directive.js +++ b/src/validation-directive.js @@ -97,7 +97,7 @@ if (!elm.isValidationCancelled) { // attempt to validate & run validation callback if user requested it - var validationPromise = attemptToValidate(value, 0); + var validationPromise = attemptToValidate(value); if(!!_validationCallback) { commonObj.runValidationCallbackOnPromise(validationPromise, _validationCallback); }