Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit f98e851

Browse files
committed
fix(input): fix bad label initialization when using static value. Fixes
1 parent be4311a commit f98e851

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/components/input/input.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ function inputTextareaDirective($mdUtil, $window, $mdAria) {
164164
function postLink(scope, element, attr, ctrls) {
165165

166166
var containerCtrl = ctrls[0];
167+
var hasNgModel = !!ctrls[1];
167168
var ngModelCtrl = ctrls[1] || $mdUtil.fakeNgModel();
168169
var isReadonly = angular.isDefined(attr.readonly);
169170

@@ -186,6 +187,13 @@ function inputTextareaDirective($mdUtil, $window, $mdAria) {
186187
setupTextarea();
187188
}
188189

190+
// If the input doesn't have an ngModel, it may have a static value. For that case,
191+
// we have to do one initial check to determine if the container should be in the
192+
// "has a value" state.
193+
if (!hasNgModel) {
194+
inputCheckValue();
195+
}
196+
189197
var isErrorGetter = containerCtrl.isErrorGetter || function() {
190198
return ngModelCtrl.$invalid && ngModelCtrl.$touched;
191199
};

src/components/input/input.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,18 @@ describe('md-input-container directive', function() {
186186
var input = el.find('input');
187187
expect(input.attr('aria-label')).toBe('baz');
188188
}));
189+
190+
it('should put the container in "has value" state when input has a static value', inject(function($rootScope, $compile) {
191+
var scope = $rootScope.$new();
192+
var template =
193+
'<md-input-container>' +
194+
'<label>Name</label>' +
195+
'<input value="Larry">' +
196+
'</md-input-container>';
197+
198+
var element = $compile(template)(scope);
199+
scope.$apply();
200+
201+
expect(element.hasClass('md-input-has-value')).toBe(true);
202+
}));
189203
});

0 commit comments

Comments
 (0)