|
35 | 35 | */ |
36 | 36 | var expression = {}; |
37 | 37 |
|
| 38 | + /** |
| 39 | + * default valid method |
| 40 | + * @type {{}} |
| 41 | + */ |
| 42 | + var validMethod = null; |
| 43 | + |
38 | 44 | /** |
39 | 45 | * default error, success message |
40 | 46 | * @type {{}} |
|
79 | 85 | return defaultMsg[msg]; |
80 | 86 | }; |
81 | 87 |
|
| 88 | + /** |
| 89 | + * allow user to set the global valid method |
| 90 | + * @param v |
| 91 | + * @returns {*} |
| 92 | + */ |
| 93 | + this.setValidMethod = function(v) { |
| 94 | + validMethod = v; |
| 95 | + }; |
| 96 | + |
| 97 | + /** |
| 98 | + * Get the valid method |
| 99 | + * @returns {*} |
| 100 | + */ |
| 101 | + this.getValidMethod = function() { |
| 102 | + return validMethod; |
| 103 | + }; |
| 104 | + |
82 | 105 | /** |
83 | 106 | * Override the errorHTML function |
84 | 107 | * @param func |
|
247 | 270 | this.$get = ['$injector', function($injector) { |
248 | 271 | setup($injector); |
249 | 272 | return { |
| 273 | + setValidMethod: this.setValidMethod, |
| 274 | + getValidMethod: this.getValidMethod, |
250 | 275 | setErrorHTML: this.setErrorHTML, |
251 | 276 | getErrorHTML: this.getErrorHTML, |
252 | 277 | setSuccessHTML: this.setSuccessHTML, |
|
556 | 581 | * Check validator |
557 | 582 | */ |
558 | 583 |
|
| 584 | + |
| 585 | + var validMethod = (angular.isUndefined(attrs.validMethod)) ? $validationProvider.getValidMethod() : attrs.validMethod; |
| 586 | + |
559 | 587 | /** |
560 | 588 | * Click submit form, check the validity when submit |
561 | 589 | */ |
|
565 | 593 |
|
566 | 594 | isValid = checkValidation(scope, element, attrs, ctrl, validation, value); |
567 | 595 |
|
568 | | - if (attrs.validMethod === 'submit') { |
| 596 | + if (validMethod === 'submit') { |
569 | 597 | // clear previous scope.$watch |
570 | 598 | watch(); |
571 | 599 | watch = scope.$watch(function() { |
|
606 | 634 | /** |
607 | 635 | * Validate blur method |
608 | 636 | */ |
609 | | - if (attrs.validMethod === 'blur') { |
| 637 | + if (validMethod === 'blur') { |
610 | 638 | element.bind('blur', function() { |
611 | 639 | var value = scope.$eval(attrs.ngModel); |
612 | 640 | scope.$apply(function() { |
|
620 | 648 | /** |
621 | 649 | * Validate submit & submit-only method |
622 | 650 | */ |
623 | | - if (attrs.validMethod === 'submit' || attrs.validMethod === 'submit-only') { |
| 651 | + if (validMethod === 'submit' || validMethod === 'submit-only') { |
624 | 652 | return; |
625 | 653 | } |
626 | 654 |
|
|
0 commit comments