Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/select/demoValidations/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<md-input-container flex="50">
<label>Favorite Color</label>
<md-select name="favoriteColor" ng-model="favoriteColor" required>
<md-option value=""></md-option>
<md-option value="red">Red</md-option>
<md-option value="blue">Blue</md-option>
<md-option value="green">Green</md-option>
Expand Down
9 changes: 6 additions & 3 deletions src/components/select/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,8 @@ function SelectDirective($mdSelect, $mdUtil, $mdConstant, $mdTheming, $mdAria, $

function inputCheckValue() {
// The select counts as having a value if one or more options are selected,
// or if the input's validity state says it has bad input (eg string in a number input)
// we must do this on nextTick as the $render is sometimes invoked on nextTick.
// or if the input's validity state says it has bad input (eg: string in a number input).
// We must do this on nextTick as the $render is sometimes invoked on nextTick.
$mdUtil.nextTick(function () {
containerCtrl && containerCtrl.setHasValue(
selectMenuCtrl.getSelectedLabels().length > 0 || (element[0].validity || {}).badInput);
Expand Down Expand Up @@ -850,7 +850,10 @@ function SelectMenuDirective($parse, $mdUtil, $mdConstant, $mdTheming) {
self.ngModel.$isEmpty = function($viewValue) {
// We have to transform the viewValue into the hashKey, because otherwise the
// OptionCtrl may not exist. Developers may have specified a trackBy function.
return !self.options[self.hashGetter($viewValue)];
var hashedValue = self.options[self.hashGetter($viewValue)] ? self.options[self.hashGetter($viewValue)].value : null;
// Base this check on the default AngularJS $isEmpty() function.
// eslint-disable-next-line no-self-compare
return !angular.isDefined(hashedValue) || hashedValue === null || hashedValue === '' || hashedValue !== hashedValue;
};

// Allow users to provide `ng-model="foo" ng-model-options="{trackBy: '$value.id'}"` so
Expand Down