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

Commit

Permalink
fix(autocomplete): updates docs, removes clear button when using a …
Browse files Browse the repository at this point in the history
…floating label

Closes #2727
  • Loading branch information
Robert Messerle committed Jun 4, 2015
1 parent 34cb8c3 commit 86b4afa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/components/autocomplete/js/autocompleteController.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,13 @@ function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $timeout, $

function select (index) {
$scope.selectedItem = self.matches[index];
$scope.searchText = getDisplayValue($scope.selectedItem) || $scope.searchText;
self.hidden = true;
self.index = 0;
self.matches = [];
//-- force form to update state for validation
elements.$.input.controller('ngModel').$setViewValue($scope.searchText);
$timeout(function () {
elements.$.input.controller('ngModel').$setViewValue(getDisplayValue($scope.selectedItem) || $scope.searchText);
});
}

function clearValue () {
Expand Down
20 changes: 11 additions & 9 deletions src/components/autocomplete/js/autocompleteDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ angular
* @param {boolean=} md-autofocus If true, will immediately focus the input element
* @param {boolean=} md-autoselect If true, the first item will be selected by default
* @param {string=} md-menu-class This will be applied to the dropdown menu for styling
* @param {string=} md-floating-label This will add a floating label to autocomplete and wrap it in `md-input-container`
*
* @usage
* ###Basic Example
Expand Down Expand Up @@ -135,14 +136,6 @@ function MdAutocomplete ($mdTheming, $mdUtil) {
ng-class="{ \'md-whiteframe-z1\': !floatingLabel }"\
role="listbox">\
' + getInputElement() + '\
<button\
type="button"\
tabindex="-1"\
ng-if="$mdAutocompleteCtrl.scope.searchText && !isDisabled"\
ng-click="$mdAutocompleteCtrl.clear()">\
<md-icon md-svg-icon="md-cancel"></md-icon>\
<span class="md-visually-hidden">Clear</span>\
</button>\
<md-progress-linear\
ng-if="$mdAutocompleteCtrl.loading"\
md-mode="indeterminate"></md-progress-linear>\
Expand Down Expand Up @@ -232,7 +225,16 @@ function MdAutocomplete ($mdTheming, $mdUtil) {
aria-autocomplete="list"\
aria-haspopup="true"\
aria-activedescendant=""\
aria-expanded="{{!$mdAutocompleteCtrl.hidden}}"/>';
aria-expanded="{{!$mdAutocompleteCtrl.hidden}}"/>\
<button\
type="button"\
tabindex="-1"\
ng-if="$mdAutocompleteCtrl.scope.searchText && !isDisabled"\
ng-click="$mdAutocompleteCtrl.clear()">\
<md-icon md-svg-icon="md-close"></md-icon>\
<span class="md-visually-hidden">Clear</span>\
</button>\
';
}
}
}
Expand Down

2 comments on commit 86b4afa

@jgoux
Copy link

@jgoux jgoux commented on 86b4afa Jun 10, 2015

Choose a reason for hiding this comment

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

Would it be possible to have to clear button visibility as a property so we can use it with the floating label template if we want ? This is really convenient for the users and the floating label template integrates perfectly with other inputs in forms.

@Codier
Copy link

@Codier Codier commented on 86b4afa Sep 4, 2015

Choose a reason for hiding this comment

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

+1 for keeping this around but making it optional.
My customers find it very useful. I had to create a custom directive to add it back now :(

Please sign in to comment.