|
9 | 9 |
|
10 | 10 | FormGroupController = (function() {
|
11 | 11 | function FormGroupController($scope) {
|
12 |
| - var unref; |
13 | 12 | this.$scope = $scope;
|
14 | 13 | this.update = bind(this.update, this);
|
15 | 14 | this.status = null;
|
16 | 15 | this.disabled = false;
|
17 | 16 | this.inputs = [];
|
18 |
| - unref = this.$scope.$watch(this.update); |
19 |
| - this.$scope.$on("$destroy", unref); |
| 17 | + this.$scope.$watch(this.update); |
20 | 18 | }
|
21 | 19 |
|
22 | 20 | FormGroupController.prototype.setParentForm = function(ctrl) {
|
|
36 | 34 | };
|
37 | 35 |
|
38 | 36 | FormGroupController.prototype.update = function() {
|
39 |
| - if (this.canValidate()) { |
40 |
| - return this.status = this.inputs.every(function(i) { |
| 37 | + if (this.disabled === false && this.canValidate()) { |
| 38 | + return this.status = (this.inputs.every(function(i) { |
41 | 39 | return i.$valid;
|
42 |
| - }) ? "success" : "error"; |
| 40 | + })) ? "success" : "error"; |
43 | 41 | } else {
|
44 | 42 | return this.status = null;
|
45 | 43 | }
|
|
59 | 57 | require: ["formGroup", "?^form"],
|
60 | 58 | controller: 'FormGroupController',
|
61 | 59 | link: function(scope, el, attrs, ctrls) {
|
62 |
| - var ctrl, dereg, ngFormCtrl; |
| 60 | + var ctrl, ngFormCtrl; |
63 | 61 | ctrl = ctrls[0], ngFormCtrl = ctrls[1];
|
64 |
| - if (el.hasClass('form-group-without-feedback') || ctrl.inputs.length === 0) { |
| 62 | + if (ctrl.inputs.length === 0) { |
65 | 63 | ctrl.disabled = true;
|
66 | 64 | return;
|
67 | 65 | }
|
68 | 66 | if (ngFormCtrl) {
|
69 | 67 | ctrl.setParentForm(ngFormCtrl);
|
70 | 68 | }
|
71 |
| - dereg = scope.$watch((function() { |
| 69 | + scope.$watch((function() { |
| 70 | + return el.hasClass('form-group-without-feedback'); |
| 71 | + }), function(value) { |
| 72 | + return ctrl.disabled = value; |
| 73 | + }); |
| 74 | + return scope.$watch((function() { |
72 | 75 | return ctrl.status;
|
73 | 76 | }), function(status) {
|
74 | 77 | el.removeClass("has-error has-success");
|
75 | 78 | if (status) {
|
76 | 79 | return el.addClass("has-" + status);
|
77 | 80 | }
|
78 | 81 | });
|
79 |
| - return scope.$on('$destroy', dereg); |
80 | 82 | }
|
81 | 83 | };
|
82 | 84 | }).directive("formControl", function() {
|
|
0 commit comments