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

Commit

Permalink
fix(input): fix bad label initialization when using static value. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jelbourn committed Aug 18, 2015
1 parent be4311a commit f98e851
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/components/input/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ function inputTextareaDirective($mdUtil, $window, $mdAria) {
function postLink(scope, element, attr, ctrls) {

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

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

// If the input doesn't have an ngModel, it may have a static value. For that case,
// we have to do one initial check to determine if the container should be in the
// "has a value" state.
if (!hasNgModel) {
inputCheckValue();
}

var isErrorGetter = containerCtrl.isErrorGetter || function() {
return ngModelCtrl.$invalid && ngModelCtrl.$touched;
};
Expand Down
14 changes: 14 additions & 0 deletions src/components/input/input.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,18 @@ describe('md-input-container directive', function() {
var input = el.find('input');
expect(input.attr('aria-label')).toBe('baz');
}));

it('should put the container in "has value" state when input has a static value', inject(function($rootScope, $compile) {
var scope = $rootScope.$new();
var template =
'<md-input-container>' +
'<label>Name</label>' +
'<input value="Larry">' +
'</md-input-container>';

var element = $compile(template)(scope);
scope.$apply();

expect(element.hasClass('md-input-has-value')).toBe(true);
}));
});

1 comment on commit f98e851

@bitoverflow
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seem to work for the 'value' attribute, but not for 'ng-value'.

Please sign in to comment.