material icon indicating copy to clipboard operation
material copied to clipboard

md-autocomplete setting search-text as selected-item

Open UsamaKhalil-KSO opened this issue 10 years ago • 8 comments

I have this

<md-autocomplete 
  md-selected-item="SelectedSupervisor"
  md-search-text="SearchTerm"
  md-delay="3000"
  md-items="supervisor in MyFilter(SearchTerm)"
  md-min-length="4"
  placeholder="Search for Supervisor"
  md-menu-class="autocomplete-custom-template">

$scope.SearchTerm is simply a string value that I use. However, whenever I click on one of the records of the autocomplete, which would be something like this:

$scope.SelectedSupervisor = {
    Id: 0,
    Name: ""
}

(Obviously, depending on the selected-item, the value would change for this variable). That value for example is set to $scope.SearchTerm, which of course makes my app crash since most functions on my app use $scope.SearchTerm itself as a string.

Why does the click on record set the value of $scope.SearchTerm as that of the selected item?

UsamaKhalil-KSO avatar Mar 13 '16 04:03 UsamaKhalil-KSO

The search text is a two-way binding. So, if the user types some text, it will obviously change, but if the component changes it, it makes sure to update the binding. The binding is used to fill the input element (since it is text-only) so users know which item was selected.

I guess I'm having a bit of trouble understanding what your exact issue is. Can you please provide a Codepen which demonstrates it so we can provide feedback?

topherfangio avatar Mar 16 '16 19:03 topherfangio

For example searchtext is a variable in scope of string type..but when user selects something from dropdown suggestion which are not string but some other objects ..it will change searchtext to selected object..

perhaps u dont need to manually assign the search text to selected item. Right now on change event its assigning. On Mar 17, 2016 3:42 AM, "Topher Fangio" [email protected] wrote:

The search text is a two-way binding. So, if the user types some text, it will obviously change, but if the component changes it, it makes sure to update the binding. The binding is used to fill the input element (since it is text-only) so users know which item was selected.

I guess I'm having a bit of trouble understanding what your exact issue is. Can you please provide a Codepen which demonstrates it so we can provide feedback?

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/angular/material/issues/7548#issuecomment-197509617

UsamaKhalil-KSO avatar Mar 19 '16 09:03 UsamaKhalil-KSO

Ah, I think I understand now. Perhaps you want to use the md-item-text attribute to convert it to a string properly?

topherfangio avatar Mar 21 '16 22:03 topherfangio

@topherfangio moved to you as you are responsible for this component

EladBezalel avatar Apr 21 '16 16:04 EladBezalel

@usamakhalil86 Did you get this working using the md-item-text as outlined above?

topherfangio avatar Apr 22 '16 19:04 topherfangio

Closing do to lack of timely response.

ThomasBurleson avatar Apr 22 '16 19:04 ThomasBurleson

Is this issue fixed ? I am facing a similar one... Sometimes if searchText is set as object causes issues to functions which expects the searchText to be String all the time.

maheshk172 avatar Oct 05 '16 11:10 maheshk172

@maheshk172 Please open a new issue and provide a Codepen so that we can better understand your issue.

topherfangio avatar Oct 24 '16 21:10 topherfangio