From 86b4afabf3fbe210635426af29ac73d2e03b70a1 Mon Sep 17 00:00:00 2001 From: Robert Messerle Date: Wed, 3 Jun 2015 17:25:16 -0700 Subject: [PATCH] fix(autocomplete): updates docs, removes `clear` button when using a floating label Closes #2727 --- .../autocomplete/js/autocompleteController.js | 5 +++-- .../autocomplete/js/autocompleteDirective.js | 20 ++++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/components/autocomplete/js/autocompleteController.js b/src/components/autocomplete/js/autocompleteController.js index 11b3d91e269..a85b9c1d09c 100644 --- a/src/components/autocomplete/js/autocompleteController.js +++ b/src/components/autocomplete/js/autocompleteController.js @@ -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 () { diff --git a/src/components/autocomplete/js/autocompleteDirective.js b/src/components/autocomplete/js/autocompleteDirective.js index 54be1abc60a..4a6836ce594 100644 --- a/src/components/autocomplete/js/autocompleteDirective.js +++ b/src/components/autocomplete/js/autocompleteDirective.js @@ -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 @@ -135,14 +136,6 @@ function MdAutocomplete ($mdTheming, $mdUtil) { ng-class="{ \'md-whiteframe-z1\': !floatingLabel }"\ role="listbox">\ ' + getInputElement() + '\ - \ - \ - Clear\ - \ \ @@ -232,7 +225,16 @@ function MdAutocomplete ($mdTheming, $mdUtil) { aria-autocomplete="list"\ aria-haspopup="true"\ aria-activedescendant=""\ - aria-expanded="{{!$mdAutocompleteCtrl.hidden}}"/>'; + aria-expanded="{{!$mdAutocompleteCtrl.hidden}}"/>\ + \ + \ + Clear\ + \ + '; } } }