Skip to content

Commit af97859

Browse files
committed
Fixes label overlapping issue when ngModel has value
1 parent 40ccf63 commit af97859

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
angular.module('angularBootstrapMaterial')
22
.directive('abmFormControl', ['isChar', function (isChar) {
33
return {
4-
/*templateUrl: 'templates/input.html',
5-
replace: true,*/
64
scope: {},
75
require: ['ngModel', '^abmFormGroup'],
86
compile: function () {
97
return function ($scope, $element, attrs, ctrls) {
108
var input = ctrls[0];
119
var formGroup = ctrls[1];
1210
if (!$element.hasClass('form-control')) // TBD checkif the condition is unnecessary
13-
$element.addClass('form-control')
11+
$element.addClass('form-control');
1412
if (!$element.attr('id')) // TBD checkif the condition is unnecessary
1513
$element.attr('id', 'form-control-' + $scope.$id);
1614
formGroup.registerControl($scope);
@@ -23,15 +21,18 @@ angular.module('angularBootstrapMaterial')
2321
})
2422
.on('blur', function () {
2523
formGroup.toggleFocus(false);
26-
if ($element.val())
27-
formGroup.toggleEmpty(false);
24+
formGroup.toggleEmpty($element.val());
2825
});
2926

3027
$scope.$watch(function () {
3128
return input.$invalid;
3229
}, formGroup.toggleError);
33-
$scope.$watch(attrs.ngModel, formGroup.toggleEmpty);
30+
$scope.$watch(function () {
31+
return input.$modelValue;
32+
}, function (newValue, oldValue) {
33+
formGroup.toggleEmpty(!newValue);
34+
});
3435
}
3536
}
36-
}
37+
};
3738
}]);

0 commit comments

Comments
 (0)