Skip to content

Commit 39d2d8a

Browse files
committed
Watch element classname to enable and disable validation
1 parent f98e14a commit 39d2d8a

File tree

4 files changed

+5854
-19
lines changed

4 files changed

+5854
-19
lines changed

index.js

+12-10
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@
99

1010
FormGroupController = (function() {
1111
function FormGroupController($scope) {
12-
var unref;
1312
this.$scope = $scope;
1413
this.update = bind(this.update, this);
1514
this.status = null;
1615
this.disabled = false;
1716
this.inputs = [];
18-
unref = this.$scope.$watch(this.update);
19-
this.$scope.$on("$destroy", unref);
17+
this.$scope.$watch(this.update);
2018
}
2119

2220
FormGroupController.prototype.setParentForm = function(ctrl) {
@@ -36,10 +34,10 @@
3634
};
3735

3836
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) {
4139
return i.$valid;
42-
}) ? "success" : "error";
40+
})) ? "success" : "error";
4341
} else {
4442
return this.status = null;
4543
}
@@ -59,24 +57,28 @@
5957
require: ["formGroup", "?^form"],
6058
controller: 'FormGroupController',
6159
link: function(scope, el, attrs, ctrls) {
62-
var ctrl, dereg, ngFormCtrl;
60+
var ctrl, ngFormCtrl;
6361
ctrl = ctrls[0], ngFormCtrl = ctrls[1];
64-
if (el.hasClass('form-group-without-feedback') || ctrl.inputs.length === 0) {
62+
if (ctrl.inputs.length === 0) {
6563
ctrl.disabled = true;
6664
return;
6765
}
6866
if (ngFormCtrl) {
6967
ctrl.setParentForm(ngFormCtrl);
7068
}
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() {
7275
return ctrl.status;
7376
}), function(status) {
7477
el.removeClass("has-error has-success");
7578
if (status) {
7679
return el.addClass("has-" + status);
7780
}
7881
});
79-
return scope.$on('$destroy', dereg);
8082
}
8183
};
8284
}).directive("formControl", function() {

index.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)