Skip to content

Commit e71b3f7

Browse files
committed
Adds watch for validation state changes
1 parent abab170 commit e71b3f7

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

‎src/scripts/directives/checkbox.js‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,26 @@ angular.module('angularBootstrapMaterial')
55
label: '@'
66
},
77
transclude: true,
8-
require: '?^abmFormGroup',
8+
require: ['?^abmFormGroup'],
99
templateUrl: 'templates/checkbox.html',
10-
link: function (scope, element, attrs, ctrl, transclude) {
11-
transclude(function (clone, scope) {
12-
element.find('abm-transclude-slot-checkbox').replaceWith(clone);
10+
link: function ($scope, $element, attrs, ctrls, transclude) {
11+
var input;
12+
var formGroup = ctrls[0];
13+
transclude(function (clone, $scope) {
14+
$element.find('abm-transclude-slot-checkbox').replaceWith(clone);
1315
}, null);
14-
if (ctrl) {
15-
var $input = element.find('input');
16-
element.find('label').on('mouseenter mouseleave', function (event) {
16+
if (formGroup) {
17+
var $input = $element.find('input');
18+
input = $input.controller('ngModel');
19+
$element.find('label').on('mouseenter mouseleave', function (event) {
1720
if ($input.prop('disabled')) return;
18-
ctrl.toggleFocus(event.type == 'mouseover');
21+
formGroup.toggleFocus(event.type == 'mouseover');
1922
});
23+
if (input) {
24+
$scope.$watch(function () {
25+
return input.$invalid;
26+
}, formGroup.toggleError);
27+
}
2028
}
2129
}
2230
}

‎src/scripts/directives/radio.js‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,23 @@ angular.module('angularBootstrapMaterial')
77
transclude: true,
88
require: '?^abmFormGroup',
99
templateUrl: 'templates/radio.html',
10-
link: function (scope, element, attrs, ctrl, transclude) {
11-
transclude(function (clone, scope) {
10+
link: function ($scope, element, attrs, formGroup, transclude) {
11+
transclude(function (clone, $scope) {
1212
element.find('abm-transclude-slot-radio').replaceWith(clone);
1313
}, null);
1414

15-
if (ctrl) {
15+
if (formGroup) {
1616
var $input = element.find('input');
17+
input = $input.controller('ngModel');
1718
element.find('label').on('mouseenter mouseleave', function (event) {
1819
if ($input.prop('disabled')) return;
19-
ctrl.toggleFocus(event.type == 'mouseover');
20+
formGroup.toggleFocus(event.type == 'mouseover');
2021
});
22+
if (input) {
23+
$scope.$watch(function () {
24+
return input.$invalid;
25+
}, formGroup.toggleError);
26+
}
2127
}
2228
}
2329
}

0 commit comments

Comments
 (0)