Skip to content

Commit bf77647

Browse files
author
Huei Tan
committed
Merge pull request #172 from lucax88x/blessed
Reset callback
2 parents d5a19b4 + 5aaa55e commit bf77647

5 files changed

Lines changed: 40 additions & 1 deletion

File tree

API.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,3 +325,24 @@ scope.validationInvalidHandler = function(message){
325325
displayMessage(message, 'error');
326326
};
327327
```
328+
329+
330+
### **Setup a global valid/invalid/reset callback in config phase**
331+
332+
```javascript
333+
// your module
334+
angular.module('yourApp', ['validation'])
335+
.config(['$validationProvider', function ($validationProvider) {
336+
validationProvider.validCallback = function(element) {
337+
$(element).parents('.validator-container:first').removeClass('has-error').addClass('has-success-tick');
338+
};
339+
validationProvider.invalidCallback = function(element) {
340+
$(element).parents('.validator-container:first').removeClass('has-success-tick').addClass('has-error');
341+
};
342+
validationProvider.resetCallback = function(element) {
343+
$(element).parents('.validator-container:first').removeClass('has-error');
344+
};
345+
}]);
346+
```
347+
348+

dist/angular-validation.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@
238238
*/
239239
this.invalidCallback = null;
240240

241+
/**
242+
* Do this function when reset is performed
243+
* @param element
244+
*/
245+
this.resetCallback = null;
246+
241247
/**
242248
* reset the specific form
243249
* @param form
@@ -286,6 +292,7 @@
286292
validate: this.validate,
287293
validCallback: this.validCallback,
288294
invalidCallback: this.invalidCallback,
295+
resetCallback: this.resetCallback,
289296
reset: this.reset
290297
};
291298
}];
@@ -574,6 +581,8 @@
574581
ctrl.$render();
575582
if (attrs.messageId) angular.element(document.querySelector('#' + attrs.messageId)).html('');
576583
else element.next().html('');
584+
585+
if ($validationProvider.resetCallback) $validationProvider.resetCallback(element);
577586
});
578587
});
579588

dist/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/provider.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,12 @@
232232
*/
233233
this.invalidCallback = null;
234234

235+
/**
236+
* Do this function when reset is performed
237+
* @param element
238+
*/
239+
this.resetCallback = null;
240+
235241
/**
236242
* reset the specific form
237243
* @param form
@@ -280,6 +286,7 @@
280286
validate: this.validate,
281287
validCallback: this.validCallback,
282288
invalidCallback: this.invalidCallback,
289+
resetCallback: this.resetCallback,
283290
reset: this.reset
284291
};
285292
}];

src/validator.directive.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@
225225
ctrl.$render();
226226
if (attrs.messageId) angular.element(document.querySelector('#' + attrs.messageId)).html('');
227227
else element.next().html('');
228+
229+
if ($validationProvider.resetCallback) $validationProvider.resetCallback(element);
228230
});
229231
});
230232

0 commit comments

Comments
 (0)